1 /* $NetBSD: scsiconf.c,v 1.131 1999/10/20 15:22:27 enami Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 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/types.h> 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/kernel.h> 61 #include <sys/proc.h> 62 #include <sys/malloc.h> 63 #include <sys/device.h> 64 #include <sys/conf.h> 65 #include <sys/fcntl.h> 66 #include <sys/scsiio.h> 67 68 #include <dev/scsipi/scsi_all.h> 69 #include <dev/scsipi/scsipi_all.h> 70 #include <dev/scsipi/scsiconf.h> 71 72 #include "locators.h" 73 74 #if 0 75 #if NCALS > 0 76 { T_PROCESSOR, T_FIXED, 1, 77 0, 0, 0 }, 78 #endif /* NCALS */ 79 #if NBLL > 0 80 { T_PROCESSOR, T_FIXED, 1, 81 "AEG ", "READER ", "V1.0" }, 82 #endif /* NBLL */ 83 #if NKIL > 0 84 { T_SCANNER, T_FIXED, 0, 85 "KODAK ", "IL Scanner 900 ", 0 }, 86 #endif /* NKIL */ 87 #endif 88 89 /* 90 * Declarations 91 */ 92 int scsi_probedev __P((struct scsibus_softc *, int, int)); 93 int scsi_probe_bus __P((int bus, int target, int lun)); 94 95 struct scsipi_device probe_switch = { 96 NULL, 97 NULL, 98 NULL, 99 NULL, 100 }; 101 102 int scsibusmatch __P((struct device *, struct cfdata *, void *)); 103 void scsibusattach __P((struct device *, struct device *, void *)); 104 int scsibusactivate __P((struct device *, enum devact)); 105 int scsibusdetach __P((struct device *, int flags)); 106 107 int scsibussubmatch __P((struct device *, struct cfdata *, void *)); 108 109 struct cfattach scsibus_ca = { 110 sizeof(struct scsibus_softc), scsibusmatch, scsibusattach, 111 scsibusdetach, scsibusactivate, 112 }; 113 114 extern struct cfdriver scsibus_cd; 115 116 int scsibusprint __P((void *, const char *)); 117 void scsibus_config_interrupts __P((struct device *)); 118 119 cdev_decl(scsibus); 120 121 int 122 scsiprint(aux, pnp) 123 void *aux; 124 const char *pnp; 125 { 126 struct scsipi_link *l = aux; 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 (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) 134 printf(" channel %d", l->scsipi_scsi.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_link *l = aux; 146 int channel; 147 148 /* 149 * Allow single-channel controllers to specify their channel 150 * in a special way, so that it's not printed. 151 */ 152 channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ? 153 l->scsipi_scsi.channel : 0; 154 155 if (cf->cf_loc[SCSICF_CHANNEL] != channel && 156 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT) 157 return (0); 158 159 return (1); 160 } 161 162 /* 163 * The routine called by the adapter boards to get all their 164 * devices configured in. 165 */ 166 void 167 scsibusattach(parent, self, aux) 168 struct device *parent, *self; 169 void *aux; 170 { 171 struct scsibus_softc *sb = (struct scsibus_softc *)self; 172 struct scsipi_link *sc_link_proto = aux; 173 size_t nbytes; 174 int i; 175 176 sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit; 177 sc_link_proto->scsipi_cmd = scsi_scsipi_cmd; 178 sc_link_proto->scsipi_interpret_sense = scsipi_interpret_sense; 179 sc_link_proto->sc_print_addr = scsi_print_addr; 180 sc_link_proto->scsipi_kill_pending = scsi_kill_pending; 181 182 sb->adapter_link = sc_link_proto; 183 sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target; 184 sb->sc_maxlun = sc_link_proto->scsipi_scsi.max_lun; 185 printf(": %d targets, %d luns per target\n", 186 sb->sc_maxtarget + 1, sb->sc_maxlun + 1); 187 188 /* Initialize shared data. */ 189 scsipi_init(); 190 191 nbytes = (sb->sc_maxtarget + 1) * sizeof(struct scsipi_link **); 192 sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF, 193 M_NOWAIT); 194 if (sb->sc_link == NULL) 195 panic("scsibusattach: can't allocate target links"); 196 197 nbytes = (((int) sb->sc_maxlun) + 1) * sizeof(struct scsipi_link *); 198 for (i = 0; i <= sb->sc_maxtarget; i++) { 199 sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes, 200 M_DEVBUF, M_NOWAIT); 201 if (sb->sc_link[i] == NULL) 202 panic("scsibusattach: can't allocate lun links"); 203 bzero(sb->sc_link[i], nbytes); 204 } 205 206 /* 207 * Defer configuration of the children until interrupts 208 * are enabled. 209 */ 210 config_interrupts(self, scsibus_config_interrupts); 211 } 212 213 void 214 scsibus_config_interrupts(self) 215 struct device *self; 216 { 217 218 #if defined(SCSI_DELAY) && SCSI_DELAY > 2 219 #else /* SCSI_DELAY > 2 */ 220 #undef SCSI_DELAY 221 #define SCSI_DELAY 2 222 #endif /* SCSI_DELAY */ 223 224 if (SCSI_DELAY > 0) { 225 printf("%s: waiting %d seconds for devices to settle...\n", 226 self->dv_xname, SCSI_DELAY); 227 /* ...an identifier we know no one will use... */ 228 (void) tsleep(scsibus_config_interrupts, PRIBIO, 229 "scsidly", SCSI_DELAY * hz); 230 } 231 232 scsi_probe_bus(self->dv_unit, -1, -1); 233 } 234 235 int 236 scsibussubmatch(parent, cf, aux) 237 struct device *parent; 238 struct cfdata *cf; 239 void *aux; 240 { 241 struct scsipibus_attach_args *sa = aux; 242 struct scsipi_link *sc_link = sa->sa_sc_link; 243 244 if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT && 245 cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target) 246 return (0); 247 if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT && 248 cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun) 249 return (0); 250 return ((*cf->cf_attach->ca_match)(parent, cf, aux)); 251 } 252 253 int 254 scsibusactivate(self, act) 255 struct device *self; 256 enum devact act; 257 { 258 struct scsibus_softc *sc = (struct scsibus_softc *) self; 259 struct scsipi_link *sc_link; 260 int target, lun, error = 0, s; 261 262 s = splbio(); 263 switch (act) { 264 case DVACT_ACTIVATE: 265 error = EOPNOTSUPP; 266 break; 267 268 case DVACT_DEACTIVATE: 269 for (target = 0; target <= sc->sc_maxtarget; target++) { 270 if (target == 271 sc->adapter_link->scsipi_scsi.adapter_target) 272 continue; 273 for (lun = 0; lun <= sc->sc_maxlun; lun++) { 274 sc_link = sc->sc_link[target][lun]; 275 if (sc_link == NULL) 276 continue; 277 error = 278 config_deactivate(sc_link->device_softc); 279 if (error) 280 goto out; 281 } 282 } 283 break; 284 } 285 out: 286 splx(s); 287 return (error); 288 } 289 290 int 291 scsibusdetach(self, flags) 292 struct device *self; 293 int flags; 294 { 295 struct scsibus_softc *sc = (struct scsibus_softc *) self; 296 struct scsipi_link *sc_link; 297 int target, lun, error; 298 299 for (target = 0; target <= sc->sc_maxtarget; target++) { 300 if (target == sc->adapter_link->scsipi_scsi.adapter_target) 301 continue; 302 for (lun = 0; lun <= sc->sc_maxlun; lun++) { 303 sc_link = sc->sc_link[target][lun]; 304 if (sc_link == NULL) 305 continue; 306 error = config_detach(sc_link->device_softc, flags); 307 if (error) 308 return (error); 309 free(sc_link, M_DEVBUF); 310 sc->sc_link[target][lun] = NULL; 311 } 312 } 313 return (0); 314 } 315 316 /* 317 * Probe the requested scsi bus. It must be already set up. 318 * -1 requests all set up scsi busses. 319 * target and lun optionally narrow the search if not -1 320 */ 321 int 322 scsi_probe_busses(bus, target, lun) 323 int bus, target, lun; 324 { 325 326 if (bus == -1) { 327 for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++) 328 if (scsibus_cd.cd_devs[bus]) 329 scsi_probe_bus(bus, target, lun); 330 return (0); 331 } else 332 return (scsi_probe_bus(bus, target, lun)); 333 } 334 335 /* 336 * Probe the requested scsi bus. It must be already set up. 337 * target and lun optionally narrow the search if not -1 338 */ 339 int 340 scsi_probe_bus(bus, target, lun) 341 int bus, target, lun; 342 { 343 struct scsibus_softc *scsi; 344 int maxtarget, mintarget, maxlun, minlun; 345 u_int8_t scsi_addr; 346 int error; 347 348 if (bus < 0 || bus >= scsibus_cd.cd_ndevs) 349 return (ENXIO); 350 scsi = scsibus_cd.cd_devs[bus]; 351 if (scsi == NULL) 352 return (ENXIO); 353 354 scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target; 355 356 if (target == -1) { 357 maxtarget = scsi->sc_maxtarget; 358 mintarget = 0; 359 } else { 360 if (target < 0 || target > scsi->sc_maxtarget) 361 return (EINVAL); 362 maxtarget = mintarget = target; 363 } 364 365 if (lun == -1) { 366 maxlun = scsi->sc_maxlun; 367 minlun = 0; 368 } else { 369 if (lun < 0 || lun > scsi->sc_maxlun) 370 return (EINVAL); 371 maxlun = minlun = lun; 372 } 373 374 if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0) 375 return (error); 376 for (target = mintarget; target <= maxtarget; target++) { 377 if (target == scsi_addr) 378 continue; 379 for (lun = minlun; lun <= maxlun; lun++) { 380 /* 381 * See if there's a device present, and configure it. 382 */ 383 if (scsi_probedev(scsi, target, lun) == 0) { 384 break; 385 } 386 /* otherwise something says we should look further */ 387 } 388 } 389 scsipi_adapter_delref(scsi->adapter_link); 390 return (0); 391 } 392 393 /* 394 * Print out autoconfiguration information for a subdevice. 395 * 396 * This is a slight abuse of 'standard' autoconfiguration semantics, 397 * because 'print' functions don't normally print the colon and 398 * device information. However, in this case that's better than 399 * either printing redundant information before the attach message, 400 * or having the device driver call a special function to print out 401 * the standard device information. 402 */ 403 int 404 scsibusprint(aux, pnp) 405 void *aux; 406 const char *pnp; 407 { 408 struct scsipibus_attach_args *sa = aux; 409 struct scsipi_inquiry_pattern *inqbuf; 410 u_int8_t type; 411 char *dtype, *qtype; 412 char vendor[33], product[65], revision[17]; 413 int target, lun; 414 415 if (pnp != NULL) 416 printf("%s", pnp); 417 418 inqbuf = &sa->sa_inqbuf; 419 420 target = sa->sa_sc_link->scsipi_scsi.target; 421 lun = sa->sa_sc_link->scsipi_scsi.lun; 422 423 type = inqbuf->type & SID_TYPE; 424 425 /* 426 * Figure out basic device type and qualifier. 427 */ 428 dtype = 0; 429 switch (inqbuf->type & SID_QUAL) { 430 case SID_QUAL_LU_OK: 431 qtype = ""; 432 break; 433 434 case SID_QUAL_LU_OFFLINE: 435 qtype = " offline"; 436 break; 437 438 case SID_QUAL_RSVD: 439 case SID_QUAL_BAD_LU: 440 panic("scsibusprint: impossible qualifier"); 441 442 default: 443 qtype = ""; 444 dtype = "vendor-unique"; 445 break; 446 } 447 if (dtype == 0) 448 dtype = scsipi_dtype(type); 449 450 scsipi_strvis(vendor, 33, inqbuf->vendor, 8); 451 scsipi_strvis(product, 65, inqbuf->product, 16); 452 scsipi_strvis(revision, 17, inqbuf->revision, 4); 453 454 printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s", 455 target, lun, vendor, product, revision, 456 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype, 457 inqbuf->removable ? "removable" : "fixed", qtype); 458 459 return (UNCONF); 460 } 461 462 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = { 463 {{T_CDROM, T_REMOV, 464 "CHINON ", "CD-ROM CDS-431 ", ""}, SDEV_NOLUNS}, 465 {{T_CDROM, T_REMOV, 466 "Chinon ", "CD-ROM CDS-525 ", ""}, SDEV_NOLUNS}, 467 {{T_CDROM, T_REMOV, 468 "CHINON ", "CD-ROM CDS-535 ", ""}, SDEV_NOLUNS}, 469 {{T_CDROM, T_REMOV, 470 "DEC ", "RRD42 (C) DEC ", ""}, SDEV_NOLUNS}, 471 {{T_CDROM, T_REMOV, 472 "DENON ", "DRD-25X ", "V"}, SDEV_NOLUNS}, 473 {{T_CDROM, T_REMOV, 474 "HP ", "C4324/C4325 ", ""}, SDEV_NOLUNS}, 475 {{T_CDROM, T_REMOV, 476 "IMS ", "CDD521/10 ", "2.06"}, SDEV_NOLUNS}, 477 {{T_CDROM, T_REMOV, 478 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, SDEV_NOLUNS}, 479 {{T_CDROM, T_REMOV, 480 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, SDEV_NOLUNS}, 481 {{T_CDROM, T_REMOV, 482 "MEDIAVIS", "CDR-H93MV ", "1.3"}, SDEV_NOLUNS}, 483 {{T_CDROM, T_REMOV, 484 "NEC ", "CD-ROM DRIVE:55 ", ""}, SDEV_NOLUNS}, 485 {{T_CDROM, T_REMOV, 486 "NEC ", "CD-ROM DRIVE:83 ", ""}, SDEV_NOLUNS}, 487 {{T_CDROM, T_REMOV, 488 "NEC ", "CD-ROM DRIVE:84 ", ""}, SDEV_NOLUNS}, 489 {{T_CDROM, T_REMOV, 490 "NEC ", "CD-ROM DRIVE:841", ""}, SDEV_NOLUNS}, 491 {{T_CDROM, T_REMOV, 492 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, SDEV_NOLUNS}, 493 {{T_CDROM, T_REMOV, 494 "SONY ", "CD-ROM CDU-541 ", ""}, SDEV_NOLUNS}, 495 {{T_CDROM, T_REMOV, 496 "SONY ", "CD-ROM CDU-55S ", ""}, SDEV_NOLUNS}, 497 {{T_CDROM, T_REMOV, 498 "SONY ", "CD-ROM CDU-561 ", ""}, SDEV_NOLUNS}, 499 {{T_CDROM, T_REMOV, 500 "SONY ", "CD-ROM CDU-8003A", ""}, SDEV_NOLUNS}, 501 {{T_CDROM, T_REMOV, 502 "SONY ", "CD-ROM CDU-8012 ", ""}, SDEV_NOLUNS}, 503 {{T_CDROM, T_REMOV, 504 "TEAC ", "CD-ROM ", "1.06"}, SDEV_NOLUNS}, 505 {{T_CDROM, T_REMOV, 506 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, SDEV_NOLUNS}, 507 {{T_CDROM, T_REMOV, 508 "TEXEL ", "CD-ROM ", "1.06"}, SDEV_NOLUNS}, 509 {{T_CDROM, T_REMOV, 510 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, SDEV_NOLUNS}, 511 {{T_CDROM, T_REMOV, 512 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS}, 513 {{T_CDROM, T_REMOV, 514 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS}, 515 {{T_CDROM, T_REMOV, 516 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS}, 517 {{T_CDROM, T_REMOV, 518 "JVC ", "R2626", ""}, SDEV_NOLUNS}, 519 {{T_DIRECT, T_FIXED, 520 "MICROP ", "1588-15MBSUN0669", ""}, SDEV_AUTOSAVE}, 521 {{T_DIRECT, T_FIXED, 522 "MICROP ", "2217-15MQ1091501", ""}, SDEV_NOSYNCCACHE}, 523 {{T_OPTICAL, T_REMOV, 524 "EPSON ", "OMD-5010 ", "3.08"}, SDEV_NOLUNS}, 525 526 {{T_DIRECT, T_FIXED, 527 "TOSHIBA ", "CD-ROM XM-3401TA", "0283"}, ADEV_CDROM|SDEV_NOLUNS}, 528 {{T_DIRECT, T_FIXED, 529 "ADAPTEC ", "AEC-4412BD", "1.2A"}, SDEV_NOMODESENSE}, 530 {{T_DIRECT, T_FIXED, 531 "DEC ", "RZ55 (C) DEC", ""}, SDEV_AUTOSAVE}, 532 {{T_DIRECT, T_FIXED, 533 "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS|SDEV_AUTOSAVE}, 534 /* Gives non-media hardware failure in response to start-unit command */ 535 {{T_DIRECT, T_FIXED, 536 "HITACHI", "DK515C", "CP16"}, SDEV_NOSTARTUNIT}, 537 {{T_DIRECT, T_FIXED, 538 "HITACHI", "DK515C", "CP15"}, SDEV_NOSTARTUNIT}, 539 {{T_DIRECT, T_FIXED, 540 "HP ", "C372", ""}, SDEV_NOTAG}, 541 {{T_DIRECT, T_FIXED, 542 "IBMRAID ", "0662S", ""}, SDEV_AUTOSAVE}, 543 {{T_DIRECT, T_FIXED, 544 "IBM ", "0663H", ""}, SDEV_AUTOSAVE}, 545 {{T_DIRECT, T_FIXED, 546 "IBM", "0664", ""}, SDEV_AUTOSAVE}, 547 {{T_DIRECT, T_FIXED, 548 "IBM ", "H3171-S2", ""}, SDEV_NOLUNS|SDEV_AUTOSAVE}, 549 {{T_DIRECT, T_FIXED, 550 "IBM ", "KZ-C", ""}, SDEV_AUTOSAVE}, 551 /* Broken IBM disk */ 552 {{T_DIRECT, T_FIXED, 553 "" , "DFRSS2F", ""}, SDEV_AUTOSAVE}, 554 {{T_DIRECT, T_REMOV, 555 "MPL ", "MC-DISK- ", ""}, SDEV_NOLUNS}, 556 {{T_DIRECT, T_FIXED, 557 "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS}, 558 {{T_DIRECT, T_FIXED, 559 "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS}, 560 {{T_DIRECT, T_FIXED, 561 "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS}, 562 {{T_DIRECT, T_FIXED, 563 "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS}, 564 {{T_DIRECT, T_FIXED, 565 "MAXTOR ", "XT-8760S", ""}, SDEV_NOLUNS}, 566 {{T_DIRECT, T_FIXED, 567 "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS}, 568 {{T_DIRECT, T_FIXED, 569 "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS}, 570 {{T_DIRECT, T_FIXED, 571 "MAXTOR ", "LXT-200S ", ""}, SDEV_NOLUNS}, 572 {{T_DIRECT, T_FIXED, 573 "MEGADRV ", "EV1000", ""}, SDEV_NOMODESENSE}, 574 {{T_DIRECT, T_FIXED, 575 "MST ", "SnapLink ", ""}, SDEV_NOLUNS}, 576 {{T_DIRECT, T_FIXED, 577 "NEC ", "D3847 ", "0307"}, SDEV_NOLUNS}, 578 {{T_DIRECT, T_FIXED, 579 "QUANTUM ", "ELS85S ", ""}, SDEV_AUTOSAVE}, 580 {{T_DIRECT, T_FIXED, 581 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS}, 582 {{T_DIRECT, T_FIXED, 583 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS}, 584 {{T_DIRECT, T_FIXED, 585 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS}, 586 {{T_DIRECT, T_FIXED, 587 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS}, 588 {{T_DIRECT, T_FIXED, 589 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS}, 590 {{T_DIRECT, T_FIXED, 591 "SEAGATE ", "ST125N ", ""}, SDEV_NOLUNS}, 592 {{T_DIRECT, T_FIXED, 593 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS}, 594 {{T_DIRECT, T_FIXED, 595 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS}, 596 {{T_DIRECT, T_FIXED, 597 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS}, 598 {{T_DIRECT, T_FIXED, 599 "SEAGATE ", "ST19171", ""}, SDEV_NOMODESENSE}, 600 {{T_DIRECT, T_FIXED, 601 "SEAGATE ", "ST34501FC ", ""}, SDEV_NOMODESENSE}, 602 {{T_DIRECT, T_FIXED, 603 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS}, 604 {{T_DIRECT, T_REMOV, 605 "iomega", "jaz 1GB", ""}, SDEV_NOMODESENSE}, 606 {{T_DIRECT, T_REMOV, 607 "IOMEGA", "ZIP 100", ""}, SDEV_NOMODESENSE}, 608 {{T_DIRECT, T_REMOV, 609 "IOMEGA", "ZIP 100", "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS}, 610 /* Letting the motor run kills floppy drives and disks quite fast. */ 611 {{T_DIRECT, T_REMOV, 612 "TEAC", "FC-1", ""}, SDEV_NOSTARTUNIT}, 613 614 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */ 615 {{T_SEQUENTIAL, T_REMOV, 616 " ", " ", " "}, SDEV_NOLUNS}, 617 {{T_SEQUENTIAL, T_REMOV, 618 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS}, 619 {{T_SEQUENTIAL, T_REMOV, 620 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS}, 621 {{T_SEQUENTIAL, T_REMOV, 622 "SONY ", "GY-10C ", ""}, SDEV_NOLUNS}, 623 {{T_SEQUENTIAL, T_REMOV, 624 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS}, 625 {{T_SEQUENTIAL, T_REMOV, 626 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNC|SDEV_NOWIDE}, 627 {{T_SEQUENTIAL, T_REMOV, 628 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS}, 629 {{T_SEQUENTIAL, T_REMOV, 630 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS}, 631 /* Following entry reported as a Tandberg 3600; ref. PR1933 */ 632 {{T_SEQUENTIAL, T_REMOV, 633 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS}, 634 /* Following entry for a Cipher ST150S; ref. PR4171 */ 635 {{T_SEQUENTIAL, T_REMOV, 636 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS}, 637 {{T_SEQUENTIAL, T_REMOV, 638 "ARCHIVE ", "Python 28454-XXX", ""}, SDEV_NOLUNS}, 639 {{T_SEQUENTIAL, T_REMOV, 640 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS}, 641 {{T_SEQUENTIAL, T_REMOV, 642 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS}, 643 {{T_SEQUENTIAL, T_REMOV, 644 "WANGTEK ", "SCSI-36", ""}, SDEV_NOLUNS}, 645 {{T_SEQUENTIAL, T_REMOV, 646 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE}, 647 {{T_SEQUENTIAL, T_REMOV, 648 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE}, 649 {{T_SEQUENTIAL, T_REMOV, 650 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE}, 651 652 {{T_SCANNER, T_FIXED, 653 "RICOH ", "IS60 ", "1R08"}, SDEV_NOLUNS}, 654 {{T_SCANNER, T_FIXED, 655 "UMAX ", "Astra 1200S ", "V2.9"}, SDEV_NOLUNS}, 656 {{T_SCANNER, T_FIXED, 657 "UMAX ", "Astra 1220S ", ""}, SDEV_NOLUNS}, 658 {{T_SCANNER, T_FIXED, 659 "UMAX ", "UMAX S-6E ", "V2.0"}, SDEV_NOLUNS}, 660 {{T_SCANNER, T_FIXED, 661 "UMAX ", "UMAX S-12 ", "V2.1"}, SDEV_NOLUNS}, 662 663 {{T_PROCESSOR, T_FIXED, 664 "LITRONIC", "PCMCIA ", ""}, SDEV_NOLUNS}, 665 666 {{T_CHANGER, T_REMOV, 667 "SONY ", "CDL1100 ", ""}, SDEV_NOLUNS}, 668 669 {{T_ENCLOSURE, T_FIXED, 670 "SUN ", "SENA ", "1.07"}, SDEV_NOLUNS}, 671 }; 672 673 /* 674 * given a target and lun, ask the device what 675 * it is, and find the correct driver table 676 * entry. 677 */ 678 int 679 scsi_probedev(scsi, target, lun) 680 struct scsibus_softc *scsi; 681 int target, lun; 682 { 683 struct scsipi_link *sc_link; 684 static struct scsipi_inquiry_data inqbuf; 685 struct scsi_quirk_inquiry_pattern *finger; 686 int checkdtype, priority, docontinue; 687 struct scsipibus_attach_args sa; 688 struct cfdata *cf; 689 690 /* 691 * Assume no more luns to search after this one. 692 * If we successfully get Inquiry data and after 693 * merging quirks we find we can probe for more 694 * luns, we will. 695 */ 696 docontinue = 0; 697 698 /* Skip this slot if it is already attached. */ 699 if (scsi->sc_link[target][lun] != NULL) 700 return (docontinue); 701 702 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT); 703 *sc_link = *scsi->adapter_link; 704 sc_link->active = 0; 705 sc_link->scsipi_scsi.target = target; 706 sc_link->scsipi_scsi.lun = lun; 707 sc_link->device = &probe_switch; 708 TAILQ_INIT(&sc_link->pending_xfers); 709 710 /* 711 * Ask the device what it is 712 */ 713 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI 714 if (target == DEBUGTARGET && lun == DEBUGLUN) 715 sc_link->flags |= DEBUGLEVEL; 716 #endif /* SCSIDEBUG */ 717 718 (void) scsipi_test_unit_ready(sc_link, 719 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST | 720 XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE); 721 722 #ifdef SCSI_2_DEF 723 /* some devices need to be told to go to SCSI2 */ 724 /* However some just explode if you tell them this.. leave it out */ 725 scsi_change_def(sc_link, XS_CTL_DISCOVERY | XS_CTL_SILENT); 726 #endif /* SCSI_2_DEF */ 727 728 /* Now go ask the device all about itself. */ 729 bzero(&inqbuf, sizeof(inqbuf)); 730 if (scsipi_inquire(sc_link, &inqbuf, XS_CTL_DISCOVERY) != 0) 731 goto bad; 732 733 { 734 int len = inqbuf.additional_length; 735 while (len < 3) 736 inqbuf.unused[len++] = '\0'; 737 while (len < 3 + 28) 738 inqbuf.unused[len++] = ' '; 739 } 740 741 sa.sa_sc_link = sc_link; 742 sa.sa_inqbuf.type = inqbuf.device; 743 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 744 T_REMOV : T_FIXED; 745 sa.sa_inqbuf.vendor = inqbuf.vendor; 746 sa.sa_inqbuf.product = inqbuf.product; 747 sa.sa_inqbuf.revision = inqbuf.revision; 748 sa.scsipi_info.scsi_version = inqbuf.version; 749 750 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch( 751 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns, 752 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]), 753 sizeof(scsi_quirk_patterns[0]), &priority); 754 755 /* 756 * Based upon the inquiry flags we got back, and if we're 757 * at SCSI-2 or better, set some limiting quirks. 758 */ 759 if ((inqbuf.version & SID_ANSII) >= 2) { 760 if ((inqbuf.flags & SID_CmdQue) == 0) 761 sc_link->quirks |= SDEV_NOTAG; 762 if ((inqbuf.flags & SID_Sync) == 0) 763 sc_link->quirks |= SDEV_NOSYNC; 764 if ((inqbuf.flags & SID_WBus16) == 0) 765 sc_link->quirks |= SDEV_NOWIDE; 766 } 767 /* 768 * Now apply any quirks from the table. 769 */ 770 if (priority != 0) 771 sc_link->quirks |= finger->quirks; 772 if ((inqbuf.version & SID_ANSII) == 0 && 773 (sc_link->quirks & SDEV_FORCELUNS) == 0) 774 sc_link->quirks |= SDEV_NOLUNS; 775 sc_link->scsipi_scsi.scsi_version = inqbuf.version; 776 777 if ((sc_link->quirks & SDEV_NOLUNS) == 0) 778 docontinue = 1; 779 780 /* 781 * note what BASIC type of device it is 782 */ 783 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0) 784 sc_link->flags |= SDEV_REMOVABLE; 785 786 /* 787 * Any device qualifier that has the top bit set (qualifier&4 != 0) 788 * is vendor specific and won't match in this switch. 789 * All we do here is throw out bad/negative responses. 790 */ 791 checkdtype = 0; 792 switch (inqbuf.device & SID_QUAL) { 793 case SID_QUAL_LU_OK: 794 case SID_QUAL_LU_OFFLINE: 795 checkdtype = 1; 796 break; 797 798 case SID_QUAL_RSVD: 799 case SID_QUAL_BAD_LU: 800 goto bad; 801 802 default: 803 break; 804 } 805 if (checkdtype) 806 switch (inqbuf.device & SID_TYPE) { 807 case T_DIRECT: 808 case T_SEQUENTIAL: 809 case T_PRINTER: 810 case T_PROCESSOR: 811 case T_WORM: 812 case T_CDROM: 813 case T_SCANNER: 814 case T_OPTICAL: 815 case T_CHANGER: 816 case T_COMM: 817 case T_IT8_1: 818 case T_IT8_2: 819 case T_STORARRAY: 820 case T_ENCLOSURE: 821 default: 822 break; 823 case T_NODEVICE: 824 goto bad; 825 } 826 827 if ((cf = config_search(scsibussubmatch, (struct device *)scsi, 828 &sa)) != NULL) { 829 scsi->sc_link[target][lun] = sc_link; 830 config_attach((struct device *)scsi, cf, &sa, scsibusprint); 831 } else { 832 scsibusprint(&sa, scsi->sc_dev.dv_xname); 833 printf(" not configured\n"); 834 goto bad; 835 } 836 837 return (docontinue); 838 839 bad: 840 free(sc_link, M_DEVBUF); 841 return (docontinue); 842 } 843 844 /****** Entry points for user control of the SCSI bus. ******/ 845 846 int 847 scsibusopen(dev, flag, fmt, p) 848 dev_t dev; 849 int flag, fmt; 850 struct proc *p; 851 { 852 struct scsibus_softc *sc; 853 int error, unit = minor(dev); 854 855 if (unit >= scsibus_cd.cd_ndevs || 856 (sc = scsibus_cd.cd_devs[unit]) == NULL) 857 return (ENXIO); 858 859 if (sc->sc_flags & SCSIBUSF_OPEN) 860 return (EBUSY); 861 862 if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0) 863 return (error); 864 865 sc->sc_flags |= SCSIBUSF_OPEN; 866 867 return (0); 868 } 869 870 int 871 scsibusclose(dev, flag, fmt, p) 872 dev_t dev; 873 int flag, fmt; 874 struct proc *p; 875 { 876 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)]; 877 878 scsipi_adapter_delref(sc->adapter_link); 879 880 sc->sc_flags &= ~SCSIBUSF_OPEN; 881 882 return (0); 883 } 884 885 int 886 scsibusioctl(dev, cmd, addr, flag, p) 887 dev_t dev; 888 u_long cmd; 889 caddr_t addr; 890 int flag; 891 struct proc *p; 892 { 893 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)]; 894 struct scsipi_link *sc_link = sc->adapter_link; 895 int error; 896 897 /* 898 * Enforce write permission for ioctls that change the 899 * state of the bus. Host adapter specific ioctls must 900 * be checked by the adapter driver. 901 */ 902 switch (cmd) { 903 case SCBUSIOSCAN: 904 case SCBUSIORESET: 905 if ((flag & FWRITE) == 0) 906 return (EBADF); 907 } 908 909 switch (cmd) { 910 case SCBUSIOSCAN: 911 { 912 struct scbusioscan_args *a = 913 (struct scbusioscan_args *)addr; 914 915 /* XXX Change interface to this function. */ 916 error = scsi_probe_busses(minor(dev), a->sa_target, 917 a->sa_lun); 918 break; 919 } 920 921 case SCBUSIORESET: 922 /* FALLTHROUGH */ 923 default: 924 if (sc_link->adapter->scsipi_ioctl == NULL) 925 error = ENOTTY; 926 else 927 error = (*sc_link->adapter->scsipi_ioctl)(sc_link, 928 cmd, addr, flag, p); 929 break; 930 } 931 932 return (error); 933 } 934