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