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