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