1 /* $NetBSD: scsiconf.c,v 1.258 2010/06/07 01:41:39 pgoyette Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 1999, 2004 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 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Originally written by Julian Elischer (julian@tfs.com) 35 * for TRW Financial Systems for use under the MACH(2.5) operating system. 36 * 37 * TRW Financial Systems, in accordance with their agreement with Carnegie 38 * Mellon University, makes this software available to CMU to distribute 39 * or use in any manner that they see fit as long as this message is kept with 40 * the software. For this reason TFS also grants any other persons or 41 * organisations permission to use or modify this software. 42 * 43 * TFS supplies this software to be publicly redistributed 44 * on the understanding that TFS is not responsible for the correct 45 * functioning of this software in any circumstances. 46 * 47 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 48 */ 49 50 #include <sys/cdefs.h> 51 __KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.258 2010/06/07 01:41:39 pgoyette Exp $"); 52 53 #include <sys/param.h> 54 #include <sys/systm.h> 55 #include <sys/kernel.h> 56 #include <sys/proc.h> 57 #include <sys/kthread.h> 58 #include <sys/malloc.h> 59 #include <sys/device.h> 60 #include <sys/conf.h> 61 #include <sys/fcntl.h> 62 #include <sys/scsiio.h> 63 #include <sys/queue.h> 64 #include <sys/simplelock.h> 65 66 #include <dev/scsipi/scsi_all.h> 67 #include <dev/scsipi/scsipi_all.h> 68 #include <dev/scsipi/scsiconf.h> 69 70 #include "locators.h" 71 72 static const struct scsipi_periphsw scsi_probe_dev = { 73 NULL, 74 NULL, 75 NULL, 76 NULL, 77 }; 78 79 struct scsi_initq { 80 struct scsipi_channel *sc_channel; 81 TAILQ_ENTRY(scsi_initq) scsi_initq; 82 }; 83 84 static TAILQ_HEAD(, scsi_initq) scsi_initq_head = 85 TAILQ_HEAD_INITIALIZER(scsi_initq_head); 86 static struct simplelock scsibus_interlock = SIMPLELOCK_INITIALIZER; 87 88 static int scsi_probe_device(struct scsibus_softc *, int, int); 89 90 static int scsibusmatch(device_t, cfdata_t, void *); 91 static void scsibusattach(device_t, device_t, void *); 92 static int scsibusdetach(device_t, int flags); 93 static int scsibusrescan(device_t, const char *, const int *); 94 static void scsidevdetached(device_t, device_t); 95 96 CFATTACH_DECL3_NEW(scsibus, sizeof(struct scsibus_softc), 97 scsibusmatch, scsibusattach, scsibusdetach, NULL, 98 scsibusrescan, scsidevdetached, DVF_DETACH_SHUTDOWN); 99 100 extern struct cfdriver scsibus_cd; 101 102 static dev_type_open(scsibusopen); 103 static dev_type_close(scsibusclose); 104 static dev_type_ioctl(scsibusioctl); 105 106 const struct cdevsw scsibus_cdevsw = { 107 scsibusopen, scsibusclose, noread, nowrite, scsibusioctl, 108 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER, 109 }; 110 111 static int scsibusprint(void *, const char *); 112 static void scsibus_config(struct scsipi_channel *, void *); 113 114 const struct scsipi_bustype scsi_bustype = { 115 SCSIPI_BUSTYPE_SCSI, 116 scsi_scsipi_cmd, 117 scsipi_interpret_sense, 118 scsi_print_addr, 119 scsi_kill_pending, 120 }; 121 122 int 123 scsiprint(void *aux, 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 aprint_normal("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 aprint_normal(" channel %d", chan->chan_channel); 135 136 return (UNCONF); 137 } 138 139 static int 140 scsibusmatch(device_t parent, cfdata_t cf, void *aux) 141 { 142 struct scsipi_channel *chan = aux; 143 144 if (chan->chan_bustype->bustype_type != SCSIPI_BUSTYPE_SCSI) 145 return 0; 146 147 if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel && 148 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT) 149 return (0); 150 151 return (1); 152 } 153 154 static void 155 scsibusattach(device_t parent, device_t self, void *aux) 156 { 157 struct scsibus_softc *sc = device_private(self); 158 struct scsipi_channel *chan = aux; 159 struct scsi_initq *scsi_initq; 160 161 if (!pmf_device_register(self, NULL, NULL)) 162 aprint_error_dev(self, "couldn't establish power handler\n"); 163 164 sc->sc_dev = self; 165 sc->sc_channel = chan; 166 chan->chan_name = device_xname(sc->sc_dev); 167 168 aprint_naive(": SCSI bus\n"); 169 aprint_normal(": %d target%s, %d lun%s per target\n", 170 chan->chan_ntargets, 171 chan->chan_ntargets == 1 ? "" : "s", 172 chan->chan_nluns, 173 chan->chan_nluns == 1 ? "" : "s"); 174 175 if (scsipi_adapter_addref(chan->chan_adapter)) 176 return; 177 178 /* Initialize the channel structure first */ 179 chan->chan_init_cb = scsibus_config; 180 chan->chan_init_cb_arg = sc; 181 182 scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK); 183 scsi_initq->sc_channel = chan; 184 TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq); 185 config_pending_incr(); 186 if (scsipi_channel_init(chan)) { 187 aprint_error_dev(sc->sc_dev, "failed to init channel\n"); 188 return; 189 } 190 } 191 192 static void 193 scsibus_config(struct scsipi_channel *chan, void *arg) 194 { 195 struct scsibus_softc *sc = arg; 196 struct scsi_initq *scsi_initq; 197 198 #ifndef SCSI_DELAY 199 #define SCSI_DELAY 2 200 #endif 201 if ((chan->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 && 202 SCSI_DELAY > 0) { 203 aprint_normal_dev(sc->sc_dev, 204 "waiting %d seconds for devices to settle...\n", 205 SCSI_DELAY); 206 /* ...an identifier we know no one will use... */ 207 (void) tsleep(scsibus_config, PRIBIO, 208 "scsidly", SCSI_DELAY * hz); 209 } 210 211 /* Make sure the devices probe in scsibus order to avoid jitter. */ 212 simple_lock(&scsibus_interlock); 213 for (;;) { 214 scsi_initq = TAILQ_FIRST(&scsi_initq_head); 215 if (scsi_initq->sc_channel == chan) 216 break; 217 ltsleep(&scsi_initq_head, PRIBIO, "scsi_initq", 0, 218 &scsibus_interlock); 219 } 220 221 simple_unlock(&scsibus_interlock); 222 223 scsi_probe_bus(sc, -1, -1); 224 225 simple_lock(&scsibus_interlock); 226 TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq); 227 simple_unlock(&scsibus_interlock); 228 229 free(scsi_initq, M_DEVBUF); 230 wakeup(&scsi_initq_head); 231 232 scsipi_adapter_delref(chan->chan_adapter); 233 234 config_pending_decr(); 235 } 236 237 static int 238 scsibusdetach(device_t self, int flags) 239 { 240 struct scsibus_softc *sc = device_private(self); 241 struct scsipi_channel *chan = sc->sc_channel; 242 struct scsipi_periph *periph; 243 int ctarget, clun; 244 struct scsipi_xfer *xs; 245 int error; 246 247 pmf_device_deregister(self); 248 249 /* 250 * Process outstanding commands (which will never complete as the 251 * controller is gone). 252 */ 253 for (ctarget = 0; ctarget < chan->chan_ntargets; ctarget++) { 254 if (ctarget == chan->chan_id) 255 continue; 256 for (clun = 0; clun < chan->chan_nluns; clun++) { 257 periph = scsipi_lookup_periph(chan, ctarget, clun); 258 if (periph == NULL) 259 continue; 260 TAILQ_FOREACH(xs, &periph->periph_xferq, device_q) { 261 callout_stop(&xs->xs_callout); 262 xs->error = XS_DRIVER_STUFFUP; 263 scsipi_done(xs); 264 } 265 } 266 } 267 268 /* 269 * Detach all of the periphs. 270 */ 271 error = scsipi_target_detach(chan, -1, -1, flags); 272 273 /* 274 * Now shut down the channel. 275 * XXX only if no errors ? 276 */ 277 scsipi_channel_shutdown(chan); 278 return (error); 279 } 280 281 /* 282 * Probe the requested scsi bus. It must be already set up. 283 * target and lun optionally narrow the search if not -1 284 */ 285 int 286 scsi_probe_bus(struct scsibus_softc *sc, int target, int lun) 287 { 288 struct scsipi_channel *chan = sc->sc_channel; 289 int maxtarget, mintarget, maxlun, minlun; 290 int error; 291 292 if (target == -1) { 293 maxtarget = chan->chan_ntargets - 1; 294 mintarget = 0; 295 } else { 296 if (target < 0 || target >= chan->chan_ntargets) 297 return (EINVAL); 298 maxtarget = mintarget = target; 299 } 300 301 if (lun == -1) { 302 maxlun = chan->chan_nluns - 1; 303 minlun = 0; 304 } else { 305 if (lun < 0 || lun >= chan->chan_nluns) 306 return (EINVAL); 307 maxlun = minlun = lun; 308 } 309 310 /* 311 * Some HBAs provide an abstracted view of the bus; give them an 312 * oppertunity to re-scan it before we do. 313 */ 314 if (chan->chan_adapter->adapt_ioctl != NULL) 315 (*chan->chan_adapter->adapt_ioctl)(chan, SCBUSIOLLSCAN, NULL, 316 0, curproc); 317 318 if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0) 319 return (error); 320 for (target = mintarget; target <= maxtarget; target++) { 321 if (target == chan->chan_id) 322 continue; 323 for (lun = minlun; lun <= maxlun; lun++) { 324 /* 325 * See if there's a device present, and configure it. 326 */ 327 if (scsi_probe_device(sc, target, lun) == 0) 328 break; 329 /* otherwise something says we should look further */ 330 } 331 332 /* 333 * Now that we've discovered all of the LUNs on this 334 * I_T Nexus, update the xfer mode for all of them 335 * that we know about. 336 */ 337 scsipi_set_xfer_mode(chan, target, 1); 338 } 339 scsipi_adapter_delref(chan->chan_adapter); 340 return (0); 341 } 342 343 static int 344 scsibusrescan(device_t sc, const char *ifattr, 345 const int *locators) 346 { 347 348 KASSERT(ifattr && !strcmp(ifattr, "scsibus")); 349 KASSERT(locators); 350 351 return (scsi_probe_bus(device_private(sc), 352 locators[SCSIBUSCF_TARGET], locators[SCSIBUSCF_LUN])); 353 } 354 355 static void 356 scsidevdetached(device_t self, device_t child) 357 { 358 struct scsibus_softc *sc = device_private(self); 359 struct scsipi_channel *chan = sc->sc_channel; 360 struct scsipi_periph *periph; 361 int target, lun; 362 363 target = device_locator(child, SCSIBUSCF_TARGET); 364 lun = device_locator(child, SCSIBUSCF_LUN); 365 366 periph = scsipi_lookup_periph(chan, target, lun); 367 KASSERT(periph->periph_dev == child); 368 369 scsipi_remove_periph(chan, periph); 370 free(periph, M_DEVBUF); 371 } 372 373 /* 374 * Print out autoconfiguration information for a subdevice. 375 * 376 * This is a slight abuse of 'standard' autoconfiguration semantics, 377 * because 'print' functions don't normally print the colon and 378 * device information. However, in this case that's better than 379 * either printing redundant information before the attach message, 380 * or having the device driver call a special function to print out 381 * the standard device information. 382 */ 383 static int 384 scsibusprint(void *aux, const char *pnp) 385 { 386 struct scsipibus_attach_args *sa = aux; 387 struct scsipi_inquiry_pattern *inqbuf; 388 u_int8_t type; 389 const char *dtype; 390 char vendor[33], product[65], revision[17]; 391 int target, lun; 392 393 if (pnp != NULL) 394 aprint_normal("%s", pnp); 395 396 inqbuf = &sa->sa_inqbuf; 397 398 target = sa->sa_periph->periph_target; 399 lun = sa->sa_periph->periph_lun; 400 type = inqbuf->type & SID_TYPE; 401 402 dtype = scsipi_dtype(type); 403 404 scsipi_strvis(vendor, 33, inqbuf->vendor, 8); 405 scsipi_strvis(product, 65, inqbuf->product, 16); 406 scsipi_strvis(revision, 17, inqbuf->revision, 4); 407 408 aprint_normal(" target %d lun %d: <%s, %s, %s> %s %s", 409 target, lun, vendor, product, revision, dtype, 410 inqbuf->removable ? "removable" : "fixed"); 411 412 return (UNCONF); 413 } 414 415 static const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = { 416 {{T_CDROM, T_REMOV, 417 "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS}, 418 {{T_CDROM, T_REMOV, 419 "CHINON ", "CD-ROM CDS-435 ", ""}, PQUIRK_NOLUNS}, 420 {{T_CDROM, T_REMOV, 421 "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS}, 422 {{T_CDROM, T_REMOV, 423 "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS}, 424 {{T_CDROM, T_REMOV, 425 "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS}, 426 {{T_CDROM, T_REMOV, 427 "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS}, 428 {{T_CDROM, T_REMOV, 429 "GENERIC ", "CRD-BP2 ", ""}, PQUIRK_NOLUNS}, 430 {{T_CDROM, T_REMOV, 431 "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS}, 432 {{T_CDROM, T_REMOV, 433 "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS}, 434 {{T_CDROM, T_REMOV, 435 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS}, 436 {{T_CDROM, T_REMOV, 437 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS}, 438 {{T_CDROM, T_REMOV, 439 "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS}, 440 {{T_CDROM, T_REMOV, 441 "NEC ", "CD-ROM DRIVE:502", ""}, PQUIRK_NOLUNS}, 442 {{T_CDROM, T_REMOV, 443 "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS}, 444 {{T_CDROM, T_REMOV, 445 "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS}, 446 {{T_CDROM, T_REMOV, 447 "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS}, 448 {{T_CDROM, T_REMOV, 449 "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS}, 450 {{T_CDROM, T_REMOV, 451 "OLYMPUS ", "CDS620E ", "1.1d"}, 452 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOCAPACITY}, 453 {{T_CDROM, T_REMOV, 454 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS}, 455 {{T_CDROM, T_REMOV, 456 "PLEXTOR ", "CD-ROM PX-4XCS ", "1.01"}, 457 PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 458 {{T_CDROM, T_REMOV, 459 "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS}, 460 {{T_CDROM, T_REMOV, 461 "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS}, 462 {{T_CDROM, T_REMOV, 463 "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS}, 464 {{T_CDROM, T_REMOV, 465 "SONY ", "CD-ROM CDU-76S", ""}, 466 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 467 {{T_CDROM, T_REMOV, 468 "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS}, 469 {{T_CDROM, T_REMOV, 470 "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS}, 471 {{T_CDROM, T_REMOV, 472 "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS}, 473 {{T_CDROM, T_REMOV, 474 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS}, 475 {{T_CDROM, T_REMOV, 476 "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS}, 477 {{T_CDROM, T_REMOV, 478 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS}, 479 {{T_CDROM, T_REMOV, 480 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS}, 481 {{T_CDROM, T_REMOV, 482 "TOSHIBA ", "XM-4101TASUNSLCD", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 483 /* "IBM CDRM00201 !F" 0724 is an IBM OEM Toshiba XM-4101BME */ 484 {{T_CDROM, T_REMOV, 485 "IBM ", "CDRM00201 !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 486 {{T_CDROM, T_REMOV, 487 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS}, 488 {{T_CDROM, T_REMOV, 489 "JVC ", "R2626", ""}, PQUIRK_NOLUNS}, 490 {{T_CDROM, T_REMOV, 491 "YAMAHA", "CRW8424S", ""}, PQUIRK_NOLUNS}, 492 {{T_CDROM, T_REMOV, 493 "NEC ", "CD-ROM DRIVE:222", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 494 495 {{T_DIRECT, T_FIXED, 496 "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE}, 497 {{T_DIRECT, T_FIXED, 498 "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE}, 499 {{T_OPTICAL, T_REMOV, 500 "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS}, 501 {{T_DIRECT, T_FIXED, 502 "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE}, 503 {{T_DIRECT, T_FIXED, 504 "ADAPTEC ", "ACB-4000", ""}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE|PQUIRK_NOMODESENSE}, 505 {{T_DIRECT, T_FIXED, 506 "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE}, 507 {{T_DIRECT, T_FIXED, 508 "EMULEX ", "MD21/S2 ESDI", "A00"}, 509 PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE}, 510 {{T_DIRECT, T_FIXED, 511 "MICROP", "1548-15MZ1077801", "HZ2P"}, PQUIRK_NOTAG}, 512 {{T_DIRECT, T_FIXED, 513 "HP ", "C372", ""}, PQUIRK_NOTAG}, 514 {{T_DIRECT, T_FIXED, 515 "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE}, 516 {{T_DIRECT, T_FIXED, 517 "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE}, 518 {{T_DIRECT, T_FIXED, 519 "IBM", "0664", ""}, PQUIRK_AUTOSAVE}, 520 {{T_DIRECT, T_FIXED, 521 /* improperly report DT-only sync mode */ 522 "IBM ", "DXHS36D", ""}, 523 PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16}, 524 {{T_DIRECT, T_FIXED, 525 "IBM ", "DXHS18Y", ""}, 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_FIXED, 536 "Initio ", "", ""}, PQUIRK_NOBIGMODESENSE}, 537 {{T_DIRECT, T_REMOV, 538 "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS}, 539 {{T_DIRECT, T_FIXED, 540 "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS}, 541 {{T_DIRECT, T_FIXED, 542 "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS}, 543 {{T_DIRECT, T_FIXED, 544 "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS}, 545 {{T_DIRECT, T_FIXED, 546 "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS}, 547 {{T_DIRECT, T_FIXED, 548 "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS}, 549 {{T_DIRECT, T_FIXED, 550 "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS}, 551 {{T_DIRECT, T_FIXED, 552 "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS}, 553 {{T_DIRECT, T_FIXED, 554 "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS}, 555 {{T_DIRECT, T_FIXED, 556 "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE}, 557 {{T_DIRECT, T_FIXED, 558 "MICROP", "1991-27MZ", ""}, PQUIRK_NOTAG}, 559 {{T_DIRECT, T_FIXED, 560 "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS}, 561 {{T_DIRECT, T_FIXED, 562 "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS}, 563 {{T_DIRECT, T_FIXED, 564 "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE}, 565 {{T_DIRECT, T_FIXED, 566 "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS}, 567 {{T_DIRECT, T_FIXED, 568 "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS}, 569 {{T_DIRECT, T_FIXED, 570 "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS}, 571 {{T_DIRECT, T_FIXED, 572 "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS}, 573 {{T_DIRECT, T_FIXED, 574 "QUANTUM ", "ATLAS IV 9 WLS", "0A0A"}, PQUIRK_CAP_NODT}, 575 {{T_DIRECT, T_FIXED, 576 "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS}, 577 {{T_DIRECT, T_FIXED, 578 "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS}, 579 {{T_DIRECT, T_FIXED, 580 "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS}, 581 {{T_DIRECT, T_FIXED, 582 "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS}, 583 {{T_DIRECT, T_FIXED, 584 "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS}, 585 {{T_DIRECT, T_FIXED, 586 "SEAGATE ", "ST318404LC ", ""}, PQUIRK_NOLUNS}, 587 {{T_DIRECT, T_FIXED, 588 "SEAGATE ", "ST15150N ", ""}, PQUIRK_NOTAG}, 589 {{T_DIRECT, T_FIXED, 590 "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE}, 591 {{T_DIRECT, T_FIXED, 592 "SEAGATE ", "ST32430N", ""}, PQUIRK_CAP_SYNC}, 593 {{T_DIRECT, T_FIXED, 594 "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE}, 595 {{T_DIRECT, T_FIXED, 596 "SEAGATE ", "SX910800N", ""}, PQUIRK_NOTAG}, 597 {{T_DIRECT, T_FIXED, 598 "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS}, 599 {{T_DIRECT, T_FIXED, 600 "MICROP ", "1924", ""}, PQUIRK_CAP_SYNC}, 601 {{T_DIRECT, T_FIXED, 602 "FUJITSU ", "M2266", ""}, PQUIRK_CAP_SYNC}, 603 {{T_DIRECT, T_FIXED, 604 "FUJITSU ", "M2624S-512 ", ""}, PQUIRK_CAP_SYNC}, 605 {{T_DIRECT, T_FIXED, 606 "SEAGATE ", "SX336704LC" , ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16}, 607 608 {{T_DIRECT, T_REMOV, 609 "IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOLUNS}, 610 {{T_DIRECT, T_REMOV, 611 "INSITE", "I325VM", ""}, PQUIRK_NOLUNS}, 612 613 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */ 614 {{T_SEQUENTIAL, T_REMOV, 615 " ", " ", " "}, PQUIRK_NOLUNS}, 616 {{T_SEQUENTIAL, T_REMOV, 617 "EMULEX ", "MT-02 QIC ", ""}, PQUIRK_NOLUNS}, 618 {{T_SEQUENTIAL, T_REMOV, 619 "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS}, 620 {{T_SEQUENTIAL, T_REMOV, 621 "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS}, 622 {{T_SEQUENTIAL, T_REMOV, 623 "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS}, 624 {{T_SEQUENTIAL, T_REMOV, 625 "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS}, 626 {{T_SEQUENTIAL, T_REMOV, 627 "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 628 {{T_SEQUENTIAL, T_REMOV, 629 "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS}, 630 {{T_SEQUENTIAL, T_REMOV, 631 "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS}, 632 /* Following entry reported as a Tandberg 3600; ref. PR1933 */ 633 {{T_SEQUENTIAL, T_REMOV, 634 "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS}, 635 /* Following entry for a Cipher ST150S; ref. PR4171 */ 636 {{T_SEQUENTIAL, T_REMOV, 637 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS}, 638 {{T_SEQUENTIAL, T_REMOV, 639 "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS}, 640 {{T_SEQUENTIAL, T_REMOV, 641 "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS}, 642 {{T_SEQUENTIAL, T_REMOV, 643 "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS}, 644 {{T_SEQUENTIAL, T_REMOV, 645 "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS}, 646 {{T_SEQUENTIAL, T_REMOV, 647 "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 648 {{T_SEQUENTIAL, T_REMOV, 649 "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 650 {{T_SEQUENTIAL, T_REMOV, 651 "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 652 {{T_SEQUENTIAL, T_REMOV, 653 "TEAC ", "MT-2ST/N50 ", ""}, PQUIRK_NOLUNS}, 654 655 {{T_SCANNER, T_FIXED, 656 "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS}, 657 {{T_SCANNER, T_FIXED, 658 "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS}, 659 {{T_SCANNER, T_FIXED, 660 "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS}, 661 {{T_SCANNER, T_FIXED, 662 "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS}, 663 {{T_SCANNER, T_FIXED, 664 "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS}, 665 {{T_SCANNER, T_FIXED, 666 "ULTIMA ", "A6000C ", ""}, PQUIRK_NOLUNS}, 667 {{T_PROCESSOR, T_FIXED, 668 "ESG-SHV", "SCA HSBP M15", ""}, 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 static int 685 scsi_probe_device(struct scsibus_softc *sc, int target, int lun) 686 { 687 struct scsipi_channel *chan = sc->sc_channel; 688 struct scsipi_periph *periph; 689 struct scsipi_inquiry_data inqbuf; 690 const struct scsi_quirk_inquiry_pattern *finger; 691 int checkdtype, priority, docontinue, quirks; 692 struct scsipibus_attach_args sa; 693 cfdata_t cf; 694 int locs[SCSIBUSCF_NLOCS]; 695 device_t chld; 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 aprint_error_dev(sc->sc_dev, 713 "cannot allocate periph for target %d lun %d\n", 714 target, lun); 715 #endif 716 return (ENOMEM); 717 } 718 periph->periph_channel = chan; 719 periph->periph_switch = &scsi_probe_dev; 720 721 periph->periph_target = target; 722 periph->periph_lun = lun; 723 periph->periph_quirks = chan->chan_defquirks; 724 725 #ifdef SCSIPI_DEBUG 726 if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI && 727 SCSIPI_DEBUG_TARGET == target && 728 SCSIPI_DEBUG_LUN == lun) 729 periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS; 730 #endif 731 732 /* 733 * Ask the device what it is 734 */ 735 736 #ifdef SCSI_2_DEF 737 /* some devices need to be told to go to SCSI2 */ 738 /* However some just explode if you tell them this.. leave it out */ 739 scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT); 740 #endif /* SCSI_2_DEF */ 741 742 /* Now go ask the device all about itself. */ 743 memset(&inqbuf, 0, sizeof(inqbuf)); 744 { 745 u_int8_t *extension = &inqbuf.flags1; 746 int len = 0; 747 while (len < 3) 748 extension[len++] = '\0'; 749 while (len < 3 + 28) 750 extension[len++] = ' '; 751 while (len < 3 + 28 + 20) 752 extension[len++] = '\0'; 753 while (len < 3 + 28 + 20 + 1) 754 extension[len++] = '\0'; 755 while (len < 3 + 28 + 20 + 1 + 1) 756 extension[len++] = '\0'; 757 while (len < 3 + 28 + 20 + 1 + 1 + (8*2)) 758 extension[len++] = ' '; 759 } 760 if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY | XS_CTL_SILENT)) 761 goto bad; 762 763 periph->periph_type = inqbuf.device & SID_TYPE; 764 if (inqbuf.dev_qual2 & SID_REMOVABLE) 765 periph->periph_flags |= PERIPH_REMOVABLE; 766 periph->periph_version = inqbuf.version & SID_ANSII; 767 768 /* 769 * Any device qualifier that has the top bit set (qualifier&4 != 0) 770 * is vendor specific and won't match in this switch. 771 * All we do here is throw out bad/negative responses. 772 */ 773 checkdtype = 0; 774 switch (inqbuf.device & SID_QUAL) { 775 case SID_QUAL_LU_PRESENT: 776 checkdtype = 1; 777 break; 778 779 case SID_QUAL_LU_NOTPRESENT: 780 case SID_QUAL_reserved: 781 case SID_QUAL_LU_NOT_SUPP: 782 goto bad; 783 784 default: 785 break; 786 } 787 788 /* Let the adapter driver handle the device separatley if it wants. */ 789 if (chan->chan_adapter->adapt_accesschk != NULL && 790 (*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf)) 791 goto bad; 792 793 if (checkdtype) { 794 switch (periph->periph_type) { 795 case T_DIRECT: 796 case T_SEQUENTIAL: 797 case T_PRINTER: 798 case T_PROCESSOR: 799 case T_WORM: 800 case T_CDROM: 801 case T_SCANNER: 802 case T_OPTICAL: 803 case T_CHANGER: 804 case T_COMM: 805 case T_IT8_1: 806 case T_IT8_2: 807 case T_STORARRAY: 808 case T_ENCLOSURE: 809 case T_SIMPLE_DIRECT: 810 case T_OPTIC_CARD_RW: 811 case T_OBJECT_STORED: 812 default: 813 break; 814 case T_NODEVICE: 815 goto bad; 816 } 817 } 818 819 sa.sa_periph = periph; 820 sa.sa_inqbuf.type = inqbuf.device; 821 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 822 T_REMOV : T_FIXED; 823 sa.sa_inqbuf.vendor = inqbuf.vendor; 824 sa.sa_inqbuf.product = inqbuf.product; 825 sa.sa_inqbuf.revision = inqbuf.revision; 826 sa.scsipi_info.scsi_version = inqbuf.version; 827 sa.sa_inqptr = &inqbuf; 828 829 finger = scsipi_inqmatch( 830 &sa.sa_inqbuf, scsi_quirk_patterns, 831 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]), 832 sizeof(scsi_quirk_patterns[0]), &priority); 833 834 if (finger != NULL) 835 quirks = finger->quirks; 836 else 837 quirks = 0; 838 839 /* 840 * Determine the operating mode capabilities of the device. 841 */ 842 if (periph->periph_version >= 2) { 843 if ((inqbuf.flags3 & SID_CmdQue) != 0 && 844 (quirks & PQUIRK_NOTAG) == 0) 845 periph->periph_cap |= PERIPH_CAP_TQING; 846 if ((inqbuf.flags3 & SID_Linked) != 0) 847 periph->periph_cap |= PERIPH_CAP_LINKCMDS; 848 if ((inqbuf.flags3 & SID_Sync) != 0 && 849 (quirks & PQUIRK_NOSYNC) == 0) 850 periph->periph_cap |= PERIPH_CAP_SYNC; 851 if ((inqbuf.flags3 & SID_WBus16) != 0 && 852 (quirks & PQUIRK_NOWIDE) == 0) 853 periph->periph_cap |= PERIPH_CAP_WIDE16; 854 if ((inqbuf.flags3 & SID_WBus32) != 0 && 855 (quirks & PQUIRK_NOWIDE) == 0) 856 periph->periph_cap |= PERIPH_CAP_WIDE32; 857 if ((inqbuf.flags3 & SID_SftRe) != 0) 858 periph->periph_cap |= PERIPH_CAP_SFTRESET; 859 if ((inqbuf.flags3 & SID_RelAdr) != 0) 860 periph->periph_cap |= PERIPH_CAP_RELADR; 861 /* SPC-2 */ 862 if (periph->periph_version >= 3 && 863 !(quirks & PQUIRK_CAP_NODT)){ 864 /* 865 * Report ST clocking though CAP_WIDExx/CAP_SYNC. 866 * If the device only supports DT, clear these 867 * flags (DT implies SYNC and WIDE) 868 */ 869 switch (inqbuf.flags4 & SID_Clocking) { 870 case SID_CLOCKING_DT_ONLY: 871 periph->periph_cap &= 872 ~(PERIPH_CAP_SYNC | 873 PERIPH_CAP_WIDE16 | 874 PERIPH_CAP_WIDE32); 875 /* FALLTHROUGH */ 876 case SID_CLOCKING_SD_DT: 877 periph->periph_cap |= PERIPH_CAP_DT; 878 break; 879 default: /* ST only or invalid */ 880 /* nothing to do */ 881 break; 882 } 883 } 884 if (periph->periph_version >= 3) { 885 if (inqbuf.flags4 & SID_IUS) 886 periph->periph_cap |= PERIPH_CAP_IUS; 887 if (inqbuf.flags4 & SID_QAS) 888 periph->periph_cap |= PERIPH_CAP_QAS; 889 } 890 } 891 if (quirks & PQUIRK_CAP_SYNC) 892 periph->periph_cap |= PERIPH_CAP_SYNC; 893 if (quirks & PQUIRK_CAP_WIDE16) 894 periph->periph_cap |= PERIPH_CAP_WIDE16; 895 896 /* 897 * Now apply any quirks from the table. 898 */ 899 periph->periph_quirks |= quirks; 900 if (periph->periph_version == 0 && 901 (periph->periph_quirks & PQUIRK_FORCELUNS) == 0) 902 periph->periph_quirks |= PQUIRK_NOLUNS; 903 904 if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0) 905 docontinue = 1; 906 907 locs[SCSIBUSCF_TARGET] = target; 908 locs[SCSIBUSCF_LUN] = lun; 909 910 if ((cf = config_search_loc(config_stdsubmatch, sc->sc_dev, 911 "scsibus", locs, &sa)) != NULL) { 912 scsipi_insert_periph(chan, periph); 913 /* 914 * XXX Can't assign periph_dev here, because we'll 915 * XXX need it before config_attach() returns. Must 916 * XXX assign it in periph driver. 917 */ 918 chld = config_attach_loc(sc->sc_dev, cf, locs, &sa, 919 scsibusprint); 920 } else { 921 scsibusprint(&sa, device_xname(sc->sc_dev)); 922 aprint_normal(" not configured\n"); 923 goto bad; 924 } 925 926 return (docontinue); 927 928 bad: 929 free(periph, M_DEVBUF); 930 return (docontinue); 931 } 932 933 /****** Entry points for user control of the SCSI bus. ******/ 934 935 static int 936 scsibusopen(dev_t dev, int flag, int fmt, 937 struct lwp *l) 938 { 939 struct scsibus_softc *sc; 940 int error, unit = minor(dev); 941 942 sc = device_lookup_private(&scsibus_cd, unit); 943 if (sc == NULL) 944 return (ENXIO); 945 946 if (sc->sc_flags & SCSIBUSF_OPEN) 947 return (EBUSY); 948 949 if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0) 950 return (error); 951 952 sc->sc_flags |= SCSIBUSF_OPEN; 953 954 return (0); 955 } 956 957 static int 958 scsibusclose(dev_t dev, int flag, int fmt, 959 struct lwp *l) 960 { 961 struct scsibus_softc *sc; 962 963 sc = device_lookup_private(&scsibus_cd, minor(dev)); 964 scsipi_adapter_delref(sc->sc_channel->chan_adapter); 965 966 sc->sc_flags &= ~SCSIBUSF_OPEN; 967 968 return (0); 969 } 970 971 static int 972 scsibusioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l) 973 { 974 struct scsibus_softc *sc; 975 struct scsipi_channel *chan; 976 int error; 977 978 sc = device_lookup_private(&scsibus_cd, minor(dev)); 979 chan = sc->sc_channel; 980 981 /* 982 * Enforce write permission for ioctls that change the 983 * state of the bus. Host adapter specific ioctls must 984 * be checked by the adapter driver. 985 */ 986 switch (cmd) { 987 case SCBUSIOSCAN: 988 case SCBUSIODETACH: 989 case SCBUSIORESET: 990 if ((flag & FWRITE) == 0) 991 return (EBADF); 992 } 993 994 switch (cmd) { 995 case SCBUSIOSCAN: 996 { 997 struct scbusioscan_args *a = 998 (struct scbusioscan_args *)addr; 999 1000 error = scsi_probe_bus(sc, a->sa_target, a->sa_lun); 1001 break; 1002 } 1003 1004 case SCBUSIODETACH: 1005 { 1006 struct scbusiodetach_args *a = 1007 (struct scbusiodetach_args *)addr; 1008 1009 error = scsipi_target_detach(chan, a->sa_target, a->sa_lun, 0); 1010 break; 1011 } 1012 1013 1014 case SCBUSIORESET: 1015 /* FALLTHROUGH */ 1016 default: 1017 if (chan->chan_adapter->adapt_ioctl == NULL) 1018 error = ENOTTY; 1019 else 1020 error = (*chan->chan_adapter->adapt_ioctl)(chan, 1021 cmd, addr, flag, l->l_proc); 1022 break; 1023 } 1024 1025 return (error); 1026 } 1027