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