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