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