scsiconf.c revision 1.137 1 /* $NetBSD: scsiconf.c,v 1.137 2000/03/19 10:33:26 sjg 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_CDROM, T_REMOV,
498 "YAMAHA", "CRW8424S", ""}, SDEV_NOLUNS},
499 {{T_DIRECT, T_FIXED,
500 "MICROP ", "1588-15MBSUN0669", ""}, SDEV_AUTOSAVE},
501 {{T_DIRECT, T_FIXED,
502 "MICROP ", "2217-15MQ1091501", ""}, SDEV_NOSYNCCACHE},
503 {{T_OPTICAL, T_REMOV,
504 "EPSON ", "OMD-5010 ", "3.08"}, SDEV_NOLUNS},
505
506 {{T_DIRECT, T_FIXED,
507 "TOSHIBA ", "CD-ROM XM-3401TA", "0283"}, ADEV_CDROM|SDEV_NOLUNS},
508 {{T_DIRECT, T_FIXED,
509 "ADAPTEC ", "AEC-4412BD", "1.2A"}, SDEV_NOMODESENSE},
510 {{T_DIRECT, T_FIXED,
511 "DEC ", "RZ55 (C) DEC", ""}, SDEV_AUTOSAVE},
512 {{T_DIRECT, T_FIXED,
513 "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS|SDEV_AUTOSAVE},
514 /* Gives non-media hardware failure in response to start-unit command */
515 {{T_DIRECT, T_FIXED,
516 "HITACHI", "DK515C", "CP16"}, SDEV_NOSTARTUNIT},
517 {{T_DIRECT, T_FIXED,
518 "HITACHI", "DK515C", "CP15"}, SDEV_NOSTARTUNIT},
519 {{T_DIRECT, T_FIXED,
520 "HP ", "C372", ""}, SDEV_NOTAG},
521 {{T_DIRECT, T_FIXED,
522 "IBMRAID ", "0662S", ""}, SDEV_AUTOSAVE},
523 {{T_DIRECT, T_FIXED,
524 "IBM ", "0663H", ""}, SDEV_AUTOSAVE},
525 {{T_DIRECT, T_FIXED,
526 "IBM", "0664", ""}, SDEV_AUTOSAVE},
527 {{T_DIRECT, T_FIXED,
528 "IBM ", "H3171-S2", ""}, SDEV_NOLUNS|SDEV_AUTOSAVE},
529 {{T_DIRECT, T_FIXED,
530 "IBM ", "KZ-C", ""}, SDEV_AUTOSAVE},
531 /* Broken IBM disk */
532 {{T_DIRECT, T_FIXED,
533 "" , "DFRSS2F", ""}, SDEV_AUTOSAVE},
534 {{T_DIRECT, T_REMOV,
535 "MPL ", "MC-DISK- ", ""}, SDEV_NOLUNS},
536 {{T_DIRECT, T_FIXED,
537 "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS},
538 {{T_DIRECT, T_FIXED,
539 "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS},
540 {{T_DIRECT, T_FIXED,
541 "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS},
542 {{T_DIRECT, T_FIXED,
543 "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS},
544 {{T_DIRECT, T_FIXED,
545 "MAXTOR ", "XT-8760S", ""}, SDEV_NOLUNS},
546 {{T_DIRECT, T_FIXED,
547 "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS},
548 {{T_DIRECT, T_FIXED,
549 "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS},
550 {{T_DIRECT, T_FIXED,
551 "MAXTOR ", "LXT-200S ", ""}, SDEV_NOLUNS},
552 {{T_DIRECT, T_FIXED,
553 "MEGADRV ", "EV1000", ""}, SDEV_NOMODESENSE},
554 {{T_DIRECT, T_FIXED,
555 "MST ", "SnapLink ", ""}, SDEV_NOLUNS},
556 {{T_DIRECT, T_FIXED,
557 "NEC ", "D3847 ", "0307"}, SDEV_NOLUNS},
558 {{T_DIRECT, T_FIXED,
559 "QUANTUM ", "ELS85S ", ""}, SDEV_AUTOSAVE},
560 {{T_DIRECT, T_FIXED,
561 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS},
562 {{T_DIRECT, T_FIXED,
563 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS},
564 {{T_DIRECT, T_FIXED,
565 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS},
566 {{T_DIRECT, T_FIXED,
567 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS},
568 {{T_DIRECT, T_FIXED,
569 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS},
570 {{T_DIRECT, T_FIXED,
571 "SEAGATE ", "ST125N ", ""}, SDEV_NOLUNS},
572 {{T_DIRECT, T_FIXED,
573 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS},
574 {{T_DIRECT, T_FIXED,
575 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS},
576 {{T_DIRECT, T_FIXED,
577 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS},
578 {{T_DIRECT, T_FIXED,
579 "SEAGATE ", "ST19171", ""}, SDEV_NOMODESENSE},
580 {{T_DIRECT, T_FIXED,
581 "SEAGATE ", "ST34501FC ", ""}, SDEV_NOMODESENSE},
582 {{T_DIRECT, T_FIXED,
583 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS},
584 {{T_DIRECT, T_REMOV,
585 "iomega", "jaz 1GB", ""}, SDEV_NOMODESENSE},
586 {{T_DIRECT, T_REMOV,
587 "IOMEGA", "ZIP 100", ""}, SDEV_NOMODESENSE},
588 {{T_DIRECT, T_REMOV,
589 "IOMEGA", "ZIP 100", "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS},
590 /* Letting the motor run kills floppy drives and disks quite fast. */
591 {{T_DIRECT, T_REMOV,
592 "TEAC", "FC-1", ""}, SDEV_NOSTARTUNIT},
593
594 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
595 {{T_SEQUENTIAL, T_REMOV,
596 " ", " ", " "}, SDEV_NOLUNS},
597 {{T_SEQUENTIAL, T_REMOV,
598 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS},
599 {{T_SEQUENTIAL, T_REMOV,
600 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS},
601 {{T_SEQUENTIAL, T_REMOV,
602 "SONY ", "GY-10C ", ""}, SDEV_NOLUNS},
603 {{T_SEQUENTIAL, T_REMOV,
604 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS},
605 {{T_SEQUENTIAL, T_REMOV,
606 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNC|SDEV_NOWIDE},
607 {{T_SEQUENTIAL, T_REMOV,
608 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS},
609 {{T_SEQUENTIAL, T_REMOV,
610 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS},
611 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
612 {{T_SEQUENTIAL, T_REMOV,
613 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS},
614 /* Following entry for a Cipher ST150S; ref. PR4171 */
615 {{T_SEQUENTIAL, T_REMOV,
616 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
617 {{T_SEQUENTIAL, T_REMOV,
618 "ARCHIVE ", "Python 28454-XXX", ""}, SDEV_NOLUNS},
619 {{T_SEQUENTIAL, T_REMOV,
620 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS},
621 {{T_SEQUENTIAL, T_REMOV,
622 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS},
623 {{T_SEQUENTIAL, T_REMOV,
624 "WANGTEK ", "SCSI-36", ""}, SDEV_NOLUNS},
625 {{T_SEQUENTIAL, T_REMOV,
626 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
627 {{T_SEQUENTIAL, T_REMOV,
628 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
629 {{T_SEQUENTIAL, T_REMOV,
630 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
631 {{T_SEQUENTIAL, T_REMOV,
632 "TEAC ", "MT-2ST/N50 ", ""}, SDEV_NOLUNS},
633
634 {{T_SCANNER, T_FIXED,
635 "RICOH ", "IS60 ", "1R08"}, SDEV_NOLUNS},
636 {{T_SCANNER, T_FIXED,
637 "UMAX ", "Astra 1200S ", "V2.9"}, SDEV_NOLUNS},
638 {{T_SCANNER, T_FIXED,
639 "UMAX ", "Astra 1220S ", ""}, SDEV_NOLUNS},
640 {{T_SCANNER, T_FIXED,
641 "UMAX ", "UMAX S-6E ", "V2.0"}, SDEV_NOLUNS},
642 {{T_SCANNER, T_FIXED,
643 "UMAX ", "UMAX S-12 ", "V2.1"}, SDEV_NOLUNS},
644 {{T_SCANNER, T_FIXED,
645 "ULTIMA ", "A6000C ", ""}, SDEV_NOLUNS},
646
647 {{T_PROCESSOR, T_FIXED,
648 "LITRONIC", "PCMCIA ", ""}, SDEV_NOLUNS},
649
650 {{T_CHANGER, T_REMOV,
651 "SONY ", "CDL1100 ", ""}, SDEV_NOLUNS},
652
653 {{T_ENCLOSURE, T_FIXED,
654 "SUN ", "SENA ", ""}, SDEV_NOLUNS},
655 };
656
657 /*
658 * given a target and lun, ask the device what
659 * it is, and find the correct driver table
660 * entry.
661 */
662 int
663 scsi_probedev(scsi, target, lun)
664 struct scsibus_softc *scsi;
665 int target, lun;
666 {
667 struct scsipi_link *sc_link;
668 static struct scsipi_inquiry_data inqbuf;
669 struct scsi_quirk_inquiry_pattern *finger;
670 int checkdtype, priority, docontinue;
671 struct scsipibus_attach_args sa;
672 struct cfdata *cf;
673
674 /*
675 * Assume no more luns to search after this one.
676 * If we successfully get Inquiry data and after
677 * merging quirks we find we can probe for more
678 * luns, we will.
679 */
680 docontinue = 0;
681
682 /* Skip this slot if it is already attached. */
683 if (scsi->sc_link[target][lun] != NULL)
684 return (docontinue);
685
686 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
687 *sc_link = *scsi->adapter_link;
688 sc_link->active = 0;
689 sc_link->scsipi_scsi.target = target;
690 sc_link->scsipi_scsi.lun = lun;
691 sc_link->device = &probe_switch;
692 TAILQ_INIT(&sc_link->pending_xfers);
693
694 /*
695 * Ask the device what it is
696 */
697 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
698 if (target == DEBUGTARGET && lun == DEBUGLUN)
699 sc_link->flags |= DEBUGLEVEL;
700 #endif /* SCSIDEBUG */
701
702 (void) scsipi_test_unit_ready(sc_link,
703 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
704 XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
705
706 #ifdef SCSI_2_DEF
707 /* some devices need to be told to go to SCSI2 */
708 /* However some just explode if you tell them this.. leave it out */
709 scsi_change_def(sc_link, XS_CTL_DISCOVERY | XS_CTL_SILENT);
710 #endif /* SCSI_2_DEF */
711
712 /* Now go ask the device all about itself. */
713 bzero(&inqbuf, sizeof(inqbuf));
714 if (scsipi_inquire(sc_link, &inqbuf, XS_CTL_DISCOVERY) != 0)
715 goto bad;
716
717 {
718 int len = inqbuf.additional_length;
719 while (len < 3)
720 inqbuf.unused[len++] = '\0';
721 while (len < 3 + 28)
722 inqbuf.unused[len++] = ' ';
723 }
724
725 sa.sa_sc_link = sc_link;
726 sa.sa_inqbuf.type = inqbuf.device;
727 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
728 T_REMOV : T_FIXED;
729 sa.sa_inqbuf.vendor = inqbuf.vendor;
730 sa.sa_inqbuf.product = inqbuf.product;
731 sa.sa_inqbuf.revision = inqbuf.revision;
732 sa.scsipi_info.scsi_version = inqbuf.version;
733 sa.sa_inqptr = &inqbuf;
734
735 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
736 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
737 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
738 sizeof(scsi_quirk_patterns[0]), &priority);
739
740 /*
741 * Based upon the inquiry flags we got back, and if we're
742 * at SCSI-2 or better, set some limiting quirks.
743 */
744 if ((inqbuf.version & SID_ANSII) >= 2) {
745 if ((inqbuf.flags & SID_CmdQue) == 0)
746 sc_link->quirks |= SDEV_NOTAG;
747 if ((inqbuf.flags & SID_Sync) == 0)
748 sc_link->quirks |= SDEV_NOSYNC;
749 if ((inqbuf.flags & SID_WBus16) == 0)
750 sc_link->quirks |= SDEV_NOWIDE;
751 }
752 /*
753 * Now apply any quirks from the table.
754 */
755 if (priority != 0)
756 sc_link->quirks |= finger->quirks;
757 if ((inqbuf.version & SID_ANSII) == 0 &&
758 (sc_link->quirks & SDEV_FORCELUNS) == 0)
759 sc_link->quirks |= SDEV_NOLUNS;
760 sc_link->scsipi_scsi.scsi_version = inqbuf.version;
761
762 if ((sc_link->quirks & SDEV_NOLUNS) == 0)
763 docontinue = 1;
764
765 /*
766 * note what BASIC type of device it is
767 */
768 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
769 sc_link->flags |= SDEV_REMOVABLE;
770
771 /*
772 * Any device qualifier that has the top bit set (qualifier&4 != 0)
773 * is vendor specific and won't match in this switch.
774 * All we do here is throw out bad/negative responses.
775 */
776 checkdtype = 0;
777 switch (inqbuf.device & SID_QUAL) {
778 case SID_QUAL_LU_OK:
779 case SID_QUAL_LU_OFFLINE:
780 checkdtype = 1;
781 break;
782
783 case SID_QUAL_RSVD:
784 case SID_QUAL_BAD_LU:
785 goto bad;
786
787 default:
788 break;
789 }
790 if (checkdtype)
791 switch (inqbuf.device & SID_TYPE) {
792 case T_DIRECT:
793 case T_SEQUENTIAL:
794 case T_PRINTER:
795 case T_PROCESSOR:
796 case T_WORM:
797 case T_CDROM:
798 case T_SCANNER:
799 case T_OPTICAL:
800 case T_CHANGER:
801 case T_COMM:
802 case T_IT8_1:
803 case T_IT8_2:
804 case T_STORARRAY:
805 case T_ENCLOSURE:
806 default:
807 break;
808 case T_NODEVICE:
809 goto bad;
810 }
811
812 if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
813 &sa)) != NULL) {
814 scsi->sc_link[target][lun] = sc_link;
815 config_attach((struct device *)scsi, cf, &sa, scsibusprint);
816 } else {
817 scsibusprint(&sa, scsi->sc_dev.dv_xname);
818 printf(" not configured\n");
819 goto bad;
820 }
821
822 return (docontinue);
823
824 bad:
825 free(sc_link, M_DEVBUF);
826 return (docontinue);
827 }
828
829 /****** Entry points for user control of the SCSI bus. ******/
830
831 int
832 scsibusopen(dev, flag, fmt, p)
833 dev_t dev;
834 int flag, fmt;
835 struct proc *p;
836 {
837 struct scsibus_softc *sc;
838 int error, unit = minor(dev);
839
840 if (unit >= scsibus_cd.cd_ndevs ||
841 (sc = scsibus_cd.cd_devs[unit]) == NULL)
842 return (ENXIO);
843
844 if (sc->sc_flags & SCSIBUSF_OPEN)
845 return (EBUSY);
846
847 if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
848 return (error);
849
850 sc->sc_flags |= SCSIBUSF_OPEN;
851
852 return (0);
853 }
854
855 int
856 scsibusclose(dev, flag, fmt, p)
857 dev_t dev;
858 int flag, fmt;
859 struct proc *p;
860 {
861 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
862
863 scsipi_adapter_delref(sc->adapter_link);
864
865 sc->sc_flags &= ~SCSIBUSF_OPEN;
866
867 return (0);
868 }
869
870 int
871 scsibusioctl(dev, cmd, addr, flag, p)
872 dev_t dev;
873 u_long cmd;
874 caddr_t addr;
875 int flag;
876 struct proc *p;
877 {
878 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
879 struct scsipi_link *sc_link = sc->adapter_link;
880 int error;
881
882 /*
883 * Enforce write permission for ioctls that change the
884 * state of the bus. Host adapter specific ioctls must
885 * be checked by the adapter driver.
886 */
887 switch (cmd) {
888 case SCBUSIOSCAN:
889 case SCBUSIORESET:
890 if ((flag & FWRITE) == 0)
891 return (EBADF);
892 }
893
894 switch (cmd) {
895 case SCBUSIOSCAN:
896 {
897 struct scbusioscan_args *a =
898 (struct scbusioscan_args *)addr;
899
900 /* XXX Change interface to this function. */
901 error = scsi_probe_busses(minor(dev), a->sa_target,
902 a->sa_lun);
903 break;
904 }
905
906 case SCBUSIORESET:
907 /* FALLTHROUGH */
908 default:
909 if (sc_link->adapter->scsipi_ioctl == NULL)
910 error = ENOTTY;
911 else
912 error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
913 cmd, addr, flag, p);
914 break;
915 }
916
917 return (error);
918 }
919