32 33#include <sys/param.h> 34#include <sys/bus.h> 35#include <sys/systm.h> 36#include <sys/types.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/time.h> 40#include <sys/conf.h> 41#include <sys/fcntl.h> 42#include <sys/md5.h> 43#include <sys/interrupt.h> 44#include <sys/sbuf.h> 45 46#include <sys/lock.h> 47#include <sys/mutex.h> 48#include <sys/sysctl.h> 49 50#include <cam/cam.h> 51#include <cam/cam_ccb.h> 52#include <cam/cam_queue.h> 53#include <cam/cam_periph.h> 54#include <cam/cam_sim.h> 55#include <cam/cam_xpt.h> 56#include <cam/cam_xpt_sim.h> 57#include <cam/cam_xpt_periph.h> 58#include <cam/cam_xpt_internal.h> 59#include <cam/cam_debug.h> 60 61#include <cam/scsi/scsi_all.h> 62#include <cam/scsi/scsi_message.h> 63#include <cam/scsi/scsi_pass.h> 64#include <machine/stdarg.h> /* for xpt_print below */ 65#include "opt_cam.h" 66 67struct scsi_quirk_entry { 68 struct scsi_inquiry_pattern inq_pat; 69 u_int8_t quirks; 70#define CAM_QUIRK_NOLUNS 0x01 71#define CAM_QUIRK_NOVPDS 0x02 72#define CAM_QUIRK_HILUNS 0x04 73#define CAM_QUIRK_NOHILUNS 0x08 74#define CAM_QUIRK_NORPTLUNS 0x10 75 u_int mintags; 76 u_int maxtags; 77}; 78#define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk)) 79 80static int cam_srch_hi = 0; 81TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi); 82static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS); 83SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0, 84 sysctl_cam_search_luns, "I", 85 "allow search above LUN 7 for SCSI3 and greater devices"); 86 87#define CAM_SCSI2_MAXLUN 8 88#define CAM_CAN_GET_SIMPLE_LUN(x, i) \ 89 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 90 RPL_LUNDATA_ATYP_PERIPH) || \ 91 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 92 RPL_LUNDATA_ATYP_FLAT)) 93#define CAM_GET_SIMPLE_LUN(lp, i, lval) \ 94 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 95 RPL_LUNDATA_ATYP_PERIPH) { \ 96 (lval) = (lp)->luns[(i)].lundata[1]; \ 97 } else { \ 98 (lval) = (lp)->luns[(i)].lundata[0]; \ 99 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \ 100 (lval) <<= 8; \ 101 (lval) |= (lp)->luns[(i)].lundata[1]; \ 102 } 103/* 104 * If we're not quirked to search <= the first 8 luns 105 * and we are either quirked to search above lun 8, 106 * or we're > SCSI-2 and we've enabled hilun searching, 107 * or we're > SCSI-2 and the last lun was a success, 108 * we can look for luns above lun 8. 109 */ 110#define CAN_SRCH_HI_SPARSE(dv) \ 111 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ 112 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ 113 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi))) 114 115#define CAN_SRCH_HI_DENSE(dv) \ 116 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ 117 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ 118 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2))) 119 120static periph_init_t probe_periph_init; 121 122static struct periph_driver probe_driver = 123{ 124 probe_periph_init, "probe", 125 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0, 126 CAM_PERIPH_DRV_EARLY 127}; 128 129PERIPHDRIVER_DECLARE(probe, probe_driver); 130 131typedef enum { 132 PROBE_TUR, 133 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */ 134 PROBE_FULL_INQUIRY, 135 PROBE_REPORT_LUNS, 136 PROBE_MODE_SENSE, 137 PROBE_SUPPORTED_VPD_LIST, 138 PROBE_DEVICE_ID, 139 PROBE_SERIAL_NUM, 140 PROBE_TUR_FOR_NEGOTIATION, 141 PROBE_INQUIRY_BASIC_DV1, 142 PROBE_INQUIRY_BASIC_DV2, 143 PROBE_DV_EXIT, 144 PROBE_DONE, 145 PROBE_INVALID 146} probe_action; 147 148static char *probe_action_text[] = { 149 "PROBE_TUR", 150 "PROBE_INQUIRY", 151 "PROBE_FULL_INQUIRY", 152 "PROBE_REPORT_LUNS", 153 "PROBE_MODE_SENSE", 154 "PROBE_SUPPORTED_VPD_LIST", 155 "PROBE_DEVICE_ID", 156 "PROBE_SERIAL_NUM", 157 "PROBE_TUR_FOR_NEGOTIATION", 158 "PROBE_INQUIRY_BASIC_DV1", 159 "PROBE_INQUIRY_BASIC_DV2", 160 "PROBE_DV_EXIT", 161 "PROBE_DONE", 162 "PROBE_INVALID" 163}; 164 165#define PROBE_SET_ACTION(softc, newaction) \ 166do { \ 167 char **text; \ 168 text = probe_action_text; \ 169 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \ 170 ("Probe %s to %s\n", text[(softc)->action], \ 171 text[(newaction)])); \ 172 (softc)->action = (newaction); \ 173} while(0) 174 175typedef enum { 176 PROBE_INQUIRY_CKSUM = 0x01, 177 PROBE_SERIAL_CKSUM = 0x02, 178 PROBE_NO_ANNOUNCE = 0x04 179} probe_flags; 180 181typedef struct { 182 TAILQ_HEAD(, ccb_hdr) request_ccbs; 183 probe_action action; 184 union ccb saved_ccb; 185 probe_flags flags; 186 MD5_CTX context; 187 u_int8_t digest[16]; 188 struct cam_periph *periph; 189} probe_softc; 190 191static const char quantum[] = "QUANTUM"; 192static const char sony[] = "SONY"; 193static const char west_digital[] = "WDIGTL"; 194static const char samsung[] = "SAMSUNG"; 195static const char seagate[] = "SEAGATE"; 196static const char microp[] = "MICROP"; 197 198static struct scsi_quirk_entry scsi_quirk_table[] = 199{ 200 { 201 /* Reports QUEUE FULL for temporary resource shortages */ 202 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" }, 203 /*quirks*/0, /*mintags*/24, /*maxtags*/32 204 }, 205 { 206 /* Reports QUEUE FULL for temporary resource shortages */ 207 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" }, 208 /*quirks*/0, /*mintags*/24, /*maxtags*/32 209 }, 210 { 211 /* Reports QUEUE FULL for temporary resource shortages */ 212 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" }, 213 /*quirks*/0, /*mintags*/24, /*maxtags*/32 214 }, 215 { 216 /* Broken tagged queuing drive */ 217 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" }, 218 /*quirks*/0, /*mintags*/0, /*maxtags*/0 219 }, 220 { 221 /* Broken tagged queuing drive */ 222 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" }, 223 /*quirks*/0, /*mintags*/0, /*maxtags*/0 224 }, 225 { 226 /* Broken tagged queuing drive */ 227 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" }, 228 /*quirks*/0, /*mintags*/0, /*maxtags*/0 229 }, 230 { 231 /* 232 * Unfortunately, the Quantum Atlas III has the same 233 * problem as the Atlas II drives above. 234 * Reported by: "Johan Granlund" <johan@granlund.nu> 235 * 236 * For future reference, the drive with the problem was: 237 * QUANTUM QM39100TD-SW N1B0 238 * 239 * It's possible that Quantum will fix the problem in later 240 * firmware revisions. If that happens, the quirk entry 241 * will need to be made specific to the firmware revisions 242 * with the problem. 243 * 244 */ 245 /* Reports QUEUE FULL for temporary resource shortages */ 246 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" }, 247 /*quirks*/0, /*mintags*/24, /*maxtags*/32 248 }, 249 { 250 /* 251 * 18 Gig Atlas III, same problem as the 9G version. 252 * Reported by: Andre Albsmeier 253 * <andre.albsmeier@mchp.siemens.de> 254 * 255 * For future reference, the drive with the problem was: 256 * QUANTUM QM318000TD-S N491 257 */ 258 /* Reports QUEUE FULL for temporary resource shortages */ 259 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" }, 260 /*quirks*/0, /*mintags*/24, /*maxtags*/32 261 }, 262 { 263 /* 264 * Broken tagged queuing drive 265 * Reported by: Bret Ford <bford@uop.cs.uop.edu> 266 * and: Martin Renters <martin@tdc.on.ca> 267 */ 268 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" }, 269 /*quirks*/0, /*mintags*/0, /*maxtags*/0 270 }, 271 /* 272 * The Seagate Medalist Pro drives have very poor write 273 * performance with anything more than 2 tags. 274 * 275 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl> 276 * Drive: <SEAGATE ST36530N 1444> 277 * 278 * Reported by: Jeremy Lea <reg@shale.csir.co.za> 279 * Drive: <SEAGATE ST34520W 1281> 280 * 281 * No one has actually reported that the 9G version 282 * (ST39140*) of the Medalist Pro has the same problem, but 283 * we're assuming that it does because the 4G and 6.5G 284 * versions of the drive are broken. 285 */ 286 { 287 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"}, 288 /*quirks*/0, /*mintags*/2, /*maxtags*/2 289 }, 290 { 291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"}, 292 /*quirks*/0, /*mintags*/2, /*maxtags*/2 293 }, 294 { 295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"}, 296 /*quirks*/0, /*mintags*/2, /*maxtags*/2 297 }, 298 { 299 /* 300 * Experiences command timeouts under load with a 301 * tag count higher than 55. 302 */ 303 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"}, 304 /*quirks*/0, /*mintags*/2, /*maxtags*/55 305 }, 306 { 307 /* 308 * Slow when tagged queueing is enabled. Write performance 309 * steadily drops off with more and more concurrent 310 * transactions. Best sequential write performance with 311 * tagged queueing turned off and write caching turned on. 312 * 313 * PR: kern/10398 314 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp> 315 * Drive: DCAS-34330 w/ "S65A" firmware. 316 * 317 * The drive with the problem had the "S65A" firmware 318 * revision, and has also been reported (by Stephen J. 319 * Roznowski <sjr@home.net>) for a drive with the "S61A" 320 * firmware revision. 321 * 322 * Although no one has reported problems with the 2 gig 323 * version of the DCAS drive, the assumption is that it 324 * has the same problems as the 4 gig version. Therefore 325 * this quirk entries disables tagged queueing for all 326 * DCAS drives. 327 */ 328 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" }, 329 /*quirks*/0, /*mintags*/0, /*maxtags*/0 330 }, 331 { 332 /* Broken tagged queuing drive */ 333 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" }, 334 /*quirks*/0, /*mintags*/0, /*maxtags*/0 335 }, 336 { 337 /* Broken tagged queuing drive */ 338 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" }, 339 /*quirks*/0, /*mintags*/0, /*maxtags*/0 340 }, 341 { 342 /* This does not support other than LUN 0 */ 343 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" }, 344 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 345 }, 346 { 347 /* 348 * Broken tagged queuing drive. 349 * Submitted by: 350 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp> 351 * in PR kern/9535 352 */ 353 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" }, 354 /*quirks*/0, /*mintags*/0, /*maxtags*/0 355 }, 356 { 357 /* 358 * Slow when tagged queueing is enabled. (1.5MB/sec versus 359 * 8MB/sec.) 360 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu> 361 * Best performance with these drives is achieved with 362 * tagged queueing turned off, and write caching turned on. 363 */ 364 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" }, 365 /*quirks*/0, /*mintags*/0, /*maxtags*/0 366 }, 367 { 368 /* 369 * Slow when tagged queueing is enabled. (1.5MB/sec versus 370 * 8MB/sec.) 371 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu> 372 * Best performance with these drives is achieved with 373 * tagged queueing turned off, and write caching turned on. 374 */ 375 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" }, 376 /*quirks*/0, /*mintags*/0, /*maxtags*/0 377 }, 378 { 379 /* 380 * Doesn't handle queue full condition correctly, 381 * so we need to limit maxtags to what the device 382 * can handle instead of determining this automatically. 383 */ 384 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" }, 385 /*quirks*/0, /*mintags*/2, /*maxtags*/32 386 }, 387 { 388 /* Really only one LUN */ 389 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" }, 390 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 391 }, 392 { 393 /* I can't believe we need a quirk for DPT volumes. */ 394 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" }, 395 CAM_QUIRK_NOLUNS, 396 /*mintags*/0, /*maxtags*/255 397 }, 398 { 399 /* 400 * Many Sony CDROM drives don't like multi-LUN probing. 401 */ 402 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" }, 403 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 404 }, 405 { 406 /* 407 * This drive doesn't like multiple LUN probing. 408 * Submitted by: Parag Patel <parag@cgt.com> 409 */ 410 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" }, 411 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 412 }, 413 { 414 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" }, 415 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 416 }, 417 { 418 /* 419 * The 8200 doesn't like multi-lun probing, and probably 420 * don't like serial number requests either. 421 */ 422 { 423 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", 424 "EXB-8200*", "*" 425 }, 426 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 427 }, 428 { 429 /* 430 * Let's try the same as above, but for a drive that says 431 * it's an IPL-6860 but is actually an EXB 8200. 432 */ 433 { 434 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", 435 "IPL-6860*", "*" 436 }, 437 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 438 }, 439 { 440 /* 441 * These Hitachi drives don't like multi-lun probing. 442 * The PR submitter has a DK319H, but says that the Linux 443 * kernel has a similar work-around for the DK312 and DK314, 444 * so all DK31* drives are quirked here. 445 * PR: misc/18793 446 * Submitted by: Paul Haddad <paul@pth.com> 447 */ 448 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" }, 449 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 450 }, 451 { 452 /* 453 * The Hitachi CJ series with J8A8 firmware apparantly has 454 * problems with tagged commands. 455 * PR: 23536 456 * Reported by: amagai@nue.org 457 */ 458 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" }, 459 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 460 }, 461 { 462 /* 463 * These are the large storage arrays. 464 * Submitted by: William Carrel <william.carrel@infospace.com> 465 */ 466 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" }, 467 CAM_QUIRK_HILUNS, 2, 1024 468 }, 469 { 470 /* 471 * This old revision of the TDC3600 is also SCSI-1, and 472 * hangs upon serial number probing. 473 */ 474 { 475 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG", 476 " TDC 3600", "U07:" 477 }, 478 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0 479 }, 480 { 481 /* 482 * Would repond to all LUNs if asked for. 483 */ 484 { 485 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER", 486 "CP150", "*" 487 }, 488 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 489 }, 490 { 491 /* 492 * Would repond to all LUNs if asked for. 493 */ 494 { 495 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY", 496 "96X2*", "*" 497 }, 498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 499 }, 500 { 501 /* Submitted by: Matthew Dodd <winter@jurai.net> */ 502 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" }, 503 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 504 }, 505 { 506 /* Submitted by: Matthew Dodd <winter@jurai.net> */ 507 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" }, 508 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 509 }, 510 { 511 /* TeraSolutions special settings for TRC-22 RAID */ 512 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" }, 513 /*quirks*/0, /*mintags*/55, /*maxtags*/255 514 }, 515 { 516 /* Veritas Storage Appliance */ 517 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" }, 518 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024 519 }, 520 { 521 /* 522 * Would respond to all LUNs. Device type and removable 523 * flag are jumper-selectable. 524 */ 525 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix", 526 "Tahiti 1", "*" 527 }, 528 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 529 }, 530 { 531 /* EasyRAID E5A aka. areca ARC-6010 */ 532 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" }, 533 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255 534 }, 535 { 536 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" }, 537 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 538 }, 539 { 540 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" }, 541 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255 542 }, 543 { 544 /* Default tagged queuing parameters for all devices */ 545 { 546 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, 547 /*vendor*/"*", /*product*/"*", /*revision*/"*" 548 }, 549 /*quirks*/0, /*mintags*/2, /*maxtags*/255 550 }, 551}; 552 553static const int scsi_quirk_table_size = 554 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table); 555 556static cam_status proberegister(struct cam_periph *periph, 557 void *arg); 558static void probeschedule(struct cam_periph *probe_periph); 559static int device_has_vpd(struct cam_ed *device, uint8_t page_id); 560static void probestart(struct cam_periph *periph, union ccb *start_ccb); 561static void proberequestdefaultnegotiation(struct cam_periph *periph); 562static int proberequestbackoff(struct cam_periph *periph, 563 struct cam_ed *device); 564static void probedone(struct cam_periph *periph, union ccb *done_ccb); 565static int probe_strange_rpl_data(struct scsi_report_luns_data *rp, 566 uint32_t maxlun); 567static void probe_purge_old(struct cam_path *path, 568 struct scsi_report_luns_data *new); 569static void probecleanup(struct cam_periph *periph); 570static void scsi_find_quirk(struct cam_ed *device); 571static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb); 572static void scsi_scan_lun(struct cam_periph *periph, 573 struct cam_path *path, cam_flags flags, 574 union ccb *ccb); 575static void xptscandone(struct cam_periph *periph, union ccb *done_ccb); 576static struct cam_ed * 577 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, 578 lun_id_t lun_id); 579static void scsi_devise_transport(struct cam_path *path); 580static void scsi_set_transfer_settings(struct ccb_trans_settings *cts, 581 struct cam_ed *device, 582 int async_update); 583static void scsi_toggle_tags(struct cam_path *path); 584static void scsi_dev_async(u_int32_t async_code, 585 struct cam_eb *bus, 586 struct cam_et *target, 587 struct cam_ed *device, 588 void *async_arg); 589static void scsi_action(union ccb *start_ccb); 590static void scsi_announce_periph(struct cam_periph *periph); 591 592static struct xpt_xport scsi_xport = { 593 .alloc_device = scsi_alloc_device, 594 .action = scsi_action, 595 .async = scsi_dev_async, 596 .announce = scsi_announce_periph, 597}; 598 599struct xpt_xport * 600scsi_get_xport(void) 601{ 602 return (&scsi_xport); 603} 604 605static void 606probe_periph_init() 607{ 608} 609 610static cam_status 611proberegister(struct cam_periph *periph, void *arg) 612{ 613 union ccb *request_ccb; /* CCB representing the probe request */ 614 cam_status status; 615 probe_softc *softc; 616 617 request_ccb = (union ccb *)arg; 618 if (request_ccb == NULL) { 619 printf("proberegister: no probe CCB, " 620 "can't register device\n"); 621 return(CAM_REQ_CMP_ERR); 622 } 623 624 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT); 625 626 if (softc == NULL) { 627 printf("proberegister: Unable to probe new device. " 628 "Unable to allocate softc\n"); 629 return(CAM_REQ_CMP_ERR); 630 } 631 TAILQ_INIT(&softc->request_ccbs); 632 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 633 periph_links.tqe); 634 softc->flags = 0; 635 periph->softc = softc; 636 softc->periph = periph; 637 softc->action = PROBE_INVALID; 638 status = cam_periph_acquire(periph); 639 if (status != CAM_REQ_CMP) { 640 return (status); 641 } 642 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n")); 643 644 /* 645 * Ensure we've waited at least a bus settle 646 * delay before attempting to probe the device. 647 * For HBAs that don't do bus resets, this won't make a difference. 648 */ 649 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset, 650 scsi_delay); 651 probeschedule(periph); 652 return(CAM_REQ_CMP); 653} 654 655static void 656probeschedule(struct cam_periph *periph) 657{ 658 struct ccb_pathinq cpi; 659 union ccb *ccb; 660 probe_softc *softc; 661 662 softc = (probe_softc *)periph->softc; 663 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 664 665 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE); 666 cpi.ccb_h.func_code = XPT_PATH_INQ; 667 xpt_action((union ccb *)&cpi); 668 669 /* 670 * If a device has gone away and another device, or the same one, 671 * is back in the same place, it should have a unit attention 672 * condition pending. It will not report the unit attention in 673 * response to an inquiry, which may leave invalid transfer 674 * negotiations in effect. The TUR will reveal the unit attention 675 * condition. Only send the TUR for lun 0, since some devices 676 * will get confused by commands other than inquiry to non-existent 677 * luns. If you think a device has gone away start your scan from 678 * lun 0. This will insure that any bogus transfer settings are 679 * invalidated. 680 * 681 * If we haven't seen the device before and the controller supports 682 * some kind of transfer negotiation, negotiate with the first 683 * sent command if no bus reset was performed at startup. This 684 * ensures that the device is not confused by transfer negotiation 685 * settings left over by loader or BIOS action. 686 */ 687 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 688 && (ccb->ccb_h.target_lun == 0)) { 689 PROBE_SET_ACTION(softc, PROBE_TUR); 690 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0 691 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) { 692 proberequestdefaultnegotiation(periph); 693 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 694 } else { 695 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 696 } 697 698 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE) 699 softc->flags |= PROBE_NO_ANNOUNCE; 700 else 701 softc->flags &= ~PROBE_NO_ANNOUNCE; 702 703 xpt_schedule(periph, CAM_PRIORITY_XPT); 704} 705 706static int 707device_has_vpd(struct cam_ed *device, uint8_t page_id) 708{ 709 int i, num_pages; 710 struct scsi_vpd_supported_pages *vpds; 711 712 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds; 713 num_pages = device->supported_vpds_len - SVPD_SUPPORTED_PAGES_HDR_LEN; 714 for (i = 0;i < num_pages;i++) 715 if (vpds->page_list[i] == page_id) 716 return 1; 717 718 return 0; 719} 720 721static void 722probestart(struct cam_periph *periph, union ccb *start_ccb) 723{ 724 /* Probe the device that our peripheral driver points to */ 725 struct ccb_scsiio *csio; 726 probe_softc *softc; 727 728 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n")); 729 730 softc = (probe_softc *)periph->softc; 731 csio = &start_ccb->csio; 732again: 733 734 switch (softc->action) { 735 case PROBE_TUR: 736 case PROBE_TUR_FOR_NEGOTIATION: 737 case PROBE_DV_EXIT: 738 { 739 scsi_test_unit_ready(csio, 740 /*retries*/4, 741 probedone, 742 MSG_SIMPLE_Q_TAG, 743 SSD_FULL_SIZE, 744 /*timeout*/60000); 745 break; 746 } 747 case PROBE_INQUIRY: 748 case PROBE_FULL_INQUIRY: 749 case PROBE_INQUIRY_BASIC_DV1: 750 case PROBE_INQUIRY_BASIC_DV2: 751 { 752 u_int inquiry_len; 753 struct scsi_inquiry_data *inq_buf; 754 755 inq_buf = &periph->path->device->inq_data; 756 757 /* 758 * If the device is currently configured, we calculate an 759 * MD5 checksum of the inquiry data, and if the serial number 760 * length is greater than 0, add the serial number data 761 * into the checksum as well. Once the inquiry and the 762 * serial number check finish, we attempt to figure out 763 * whether we still have the same device. 764 */ 765 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 766 767 MD5Init(&softc->context); 768 MD5Update(&softc->context, (unsigned char *)inq_buf, 769 sizeof(struct scsi_inquiry_data)); 770 softc->flags |= PROBE_INQUIRY_CKSUM; 771 if (periph->path->device->serial_num_len > 0) { 772 MD5Update(&softc->context, 773 periph->path->device->serial_num, 774 periph->path->device->serial_num_len); 775 softc->flags |= PROBE_SERIAL_CKSUM; 776 } 777 MD5Final(softc->digest, &softc->context); 778 } 779 780 if (softc->action == PROBE_INQUIRY) 781 inquiry_len = SHORT_INQUIRY_LENGTH; 782 else 783 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf); 784 785 /* 786 * Some parallel SCSI devices fail to send an 787 * ignore wide residue message when dealing with 788 * odd length inquiry requests. Round up to be 789 * safe. 790 */ 791 inquiry_len = roundup2(inquiry_len, 2); 792 793 if (softc->action == PROBE_INQUIRY_BASIC_DV1 794 || softc->action == PROBE_INQUIRY_BASIC_DV2) { 795 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT); 796 } 797 if (inq_buf == NULL) { 798 xpt_print(periph->path, "malloc failure- skipping Basic" 799 "Domain Validation\n"); 800 PROBE_SET_ACTION(softc, PROBE_DV_EXIT); 801 scsi_test_unit_ready(csio, 802 /*retries*/4, 803 probedone, 804 MSG_SIMPLE_Q_TAG, 805 SSD_FULL_SIZE, 806 /*timeout*/60000); 807 break; 808 } 809 scsi_inquiry(csio, 810 /*retries*/4, 811 probedone, 812 MSG_SIMPLE_Q_TAG, 813 (u_int8_t *)inq_buf, 814 inquiry_len, 815 /*evpd*/FALSE, 816 /*page_code*/0, 817 SSD_MIN_SIZE, 818 /*timeout*/60 * 1000); 819 break; 820 } 821 case PROBE_REPORT_LUNS: 822 { 823 void *rp; 824 825 rp = malloc(periph->path->target->rpl_size, 826 M_CAMXPT, M_NOWAIT | M_ZERO); 827 if (rp == NULL) { 828 struct scsi_inquiry_data *inq_buf; 829 inq_buf = &periph->path->device->inq_data; 830 xpt_print(periph->path, 831 "Unable to alloc report luns storage\n"); 832 if (INQ_DATA_TQ_ENABLED(inq_buf)) 833 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); 834 else 835 PROBE_SET_ACTION(softc, 836 PROBE_SUPPORTED_VPD_LIST); 837 goto again; 838 } 839 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG, 840 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size, 841 SSD_FULL_SIZE, 60000); break; 842 break; 843 } 844 case PROBE_MODE_SENSE: 845 { 846 void *mode_buf; 847 int mode_buf_len; 848 849 mode_buf_len = sizeof(struct scsi_mode_header_6) 850 + sizeof(struct scsi_mode_blk_desc) 851 + sizeof(struct scsi_control_page); 852 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT); 853 if (mode_buf != NULL) { 854 scsi_mode_sense(csio, 855 /*retries*/4, 856 probedone, 857 MSG_SIMPLE_Q_TAG, 858 /*dbd*/FALSE, 859 SMS_PAGE_CTRL_CURRENT, 860 SMS_CONTROL_MODE_PAGE, 861 mode_buf, 862 mode_buf_len, 863 SSD_FULL_SIZE, 864 /*timeout*/60000); 865 break; 866 } 867 xpt_print(periph->path, "Unable to mode sense control page - " 868 "malloc failure\n"); 869 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); 870 } 871 /* FALLTHROUGH */ 872 case PROBE_SUPPORTED_VPD_LIST: 873 { 874 struct scsi_vpd_supported_page_list *vpd_list; 875 struct cam_ed *device; 876 877 vpd_list = NULL; 878 device = periph->path->device; 879 880 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0) 881 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT, 882 M_NOWAIT | M_ZERO); 883 884 if (vpd_list != NULL) { 885 scsi_inquiry(csio, 886 /*retries*/4, 887 probedone, 888 MSG_SIMPLE_Q_TAG, 889 (u_int8_t *)vpd_list, 890 sizeof(*vpd_list), 891 /*evpd*/TRUE, 892 SVPD_SUPPORTED_PAGE_LIST, 893 SSD_MIN_SIZE, 894 /*timeout*/60 * 1000); 895 break; 896 } 897 /* 898 * We'll have to do without, let our probedone 899 * routine finish up for us. 900 */ 901 start_ccb->csio.data_ptr = NULL; 902 probedone(periph, start_ccb); 903 return; 904 } 905 case PROBE_DEVICE_ID: 906 { 907 struct scsi_vpd_device_id *devid; 908 struct cam_ed *device; 909 910 devid = NULL; 911 device = periph->path->device; 912 if (device_has_vpd(device, SVPD_DEVICE_ID)) 913 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT, 914 M_NOWAIT | M_ZERO); 915 916 if (devid != NULL) { 917 scsi_inquiry(csio, 918 /*retries*/4, 919 probedone, 920 MSG_SIMPLE_Q_TAG, 921 (uint8_t *)devid, 922 SVPD_DEVICE_ID_MAX_SIZE, 923 /*evpd*/TRUE, 924 SVPD_DEVICE_ID, 925 SSD_MIN_SIZE, 926 /*timeout*/60 * 1000); 927 break; 928 } 929 /* 930 * We'll have to do without, let our probedone 931 * routine finish up for us. 932 */ 933 start_ccb->csio.data_ptr = NULL; 934 probedone(periph, start_ccb); 935 return; 936 } 937 case PROBE_SERIAL_NUM: 938 { 939 struct scsi_vpd_unit_serial_number *serial_buf; 940 struct cam_ed* device; 941 942 serial_buf = NULL; 943 device = periph->path->device; 944 if (device->serial_num != NULL) { 945 free(device->serial_num, M_CAMXPT); 946 device->serial_num = NULL; 947 device->serial_num_len = 0; 948 } 949 950 if (device_has_vpd(device, SVPD_UNIT_SERIAL_NUMBER)) 951 serial_buf = (struct scsi_vpd_unit_serial_number *) 952 malloc(sizeof(*serial_buf), M_CAMXPT, 953 M_NOWAIT|M_ZERO); 954 955 if (serial_buf != NULL) { 956 scsi_inquiry(csio, 957 /*retries*/4, 958 probedone, 959 MSG_SIMPLE_Q_TAG, 960 (u_int8_t *)serial_buf, 961 sizeof(*serial_buf), 962 /*evpd*/TRUE, 963 SVPD_UNIT_SERIAL_NUMBER, 964 SSD_MIN_SIZE, 965 /*timeout*/60 * 1000); 966 break; 967 } 968 /* 969 * We'll have to do without, let our probedone 970 * routine finish up for us. 971 */ 972 start_ccb->csio.data_ptr = NULL; 973 probedone(periph, start_ccb); 974 return; 975 } 976 default: 977 panic("probestart: invalid action state 0x%x\n", softc->action); 978 } 979 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE; 980 xpt_action(start_ccb); 981} 982 983static void 984proberequestdefaultnegotiation(struct cam_periph *periph) 985{ 986 struct ccb_trans_settings cts; 987 988 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); 989 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 990 cts.type = CTS_TYPE_USER_SETTINGS; 991 xpt_action((union ccb *)&cts); 992 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 993 return; 994 } 995 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 996 cts.type = CTS_TYPE_CURRENT_SETTINGS; 997 xpt_action((union ccb *)&cts); 998} 999 1000/* 1001 * Backoff Negotiation Code- only pertinent for SPI devices. 1002 */ 1003static int 1004proberequestbackoff(struct cam_periph *periph, struct cam_ed *device) 1005{ 1006 struct ccb_trans_settings cts; 1007 struct ccb_trans_settings_spi *spi; 1008 1009 memset(&cts, 0, sizeof (cts)); 1010 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); 1011 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 1012 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1013 xpt_action((union ccb *)&cts); 1014 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1015 if (bootverbose) { 1016 xpt_print(periph->path, 1017 "failed to get current device settings\n"); 1018 } 1019 return (0); 1020 } 1021 if (cts.transport != XPORT_SPI) { 1022 if (bootverbose) { 1023 xpt_print(periph->path, "not SPI transport\n"); 1024 } 1025 return (0); 1026 } 1027 spi = &cts.xport_specific.spi; 1028 1029 /* 1030 * We cannot renegotiate sync rate if we don't have one. 1031 */ 1032 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) { 1033 if (bootverbose) { 1034 xpt_print(periph->path, "no sync rate known\n"); 1035 } 1036 return (0); 1037 } 1038 1039 /* 1040 * We'll assert that we don't have to touch PPR options- the 1041 * SIM will see what we do with period and offset and adjust 1042 * the PPR options as appropriate. 1043 */ 1044 1045 /* 1046 * A sync rate with unknown or zero offset is nonsensical. 1047 * A sync period of zero means Async. 1048 */ 1049 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0 1050 || spi->sync_offset == 0 || spi->sync_period == 0) { 1051 if (bootverbose) { 1052 xpt_print(periph->path, "no sync rate available\n"); 1053 } 1054 return (0); 1055 } 1056 1057 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) { 1058 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1059 ("hit async: giving up on DV\n")); 1060 return (0); 1061 } 1062 1063 1064 /* 1065 * Jump sync_period up by one, but stop at 5MHz and fall back to Async. 1066 * We don't try to remember 'last' settings to see if the SIM actually 1067 * gets into the speed we want to set. We check on the SIM telling 1068 * us that a requested speed is bad, but otherwise don't try and 1069 * check the speed due to the asynchronous and handshake nature 1070 * of speed setting. 1071 */ 1072 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET; 1073 for (;;) { 1074 spi->sync_period++; 1075 if (spi->sync_period >= 0xf) { 1076 spi->sync_period = 0; 1077 spi->sync_offset = 0; 1078 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1079 ("setting to async for DV\n")); 1080 /* 1081 * Once we hit async, we don't want to try 1082 * any more settings. 1083 */ 1084 device->flags |= CAM_DEV_DV_HIT_BOTTOM; 1085 } else if (bootverbose) { 1086 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1087 ("DV: period 0x%x\n", spi->sync_period)); 1088 printf("setting period to 0x%x\n", spi->sync_period); 1089 } 1090 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 1091 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1092 xpt_action((union ccb *)&cts); 1093 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1094 break; 1095 } 1096 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1097 ("DV: failed to set period 0x%x\n", spi->sync_period)); 1098 if (spi->sync_period == 0) { 1099 return (0); 1100 } 1101 } 1102 return (1); 1103} 1104 1105#define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP) 1106 1107static void 1108probedone(struct cam_periph *periph, union ccb *done_ccb) 1109{ 1110 probe_softc *softc; 1111 struct cam_path *path; 1112 u_int32_t priority; 1113 1114 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n")); 1115 1116 softc = (probe_softc *)periph->softc; 1117 path = done_ccb->ccb_h.path; 1118 priority = done_ccb->ccb_h.pinfo.priority; 1119 1120 switch (softc->action) { 1121 case PROBE_TUR: 1122 { 1123 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1124 1125 if (cam_periph_error(done_ccb, 0, 1126 SF_NO_PRINT, NULL) == ERESTART) { 1127out: 1128 /* Drop freeze taken due to CAM_DEV_QFREEZE */ 1129 cam_release_devq(path, 0, 0, 0, FALSE); 1130 return; 1131 } 1132 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 1133 /* Don't wedge the queue */ 1134 xpt_release_devq(done_ccb->ccb_h.path, 1135 /*count*/1, 1136 /*run_queue*/TRUE); 1137 } 1138 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 1139 xpt_release_ccb(done_ccb); 1140 xpt_schedule(periph, priority); 1141 goto out; 1142 } 1143 case PROBE_INQUIRY: 1144 case PROBE_FULL_INQUIRY: 1145 { 1146 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1147 struct scsi_inquiry_data *inq_buf; 1148 u_int8_t periph_qual; 1149 1150 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; 1151 inq_buf = &path->device->inq_data; 1152 1153 periph_qual = SID_QUAL(inq_buf); 1154 1155 if (periph_qual == SID_QUAL_LU_CONNECTED) { 1156 u_int8_t len; 1157 1158 /* 1159 * We conservatively request only 1160 * SHORT_INQUIRY_LEN bytes of inquiry 1161 * information during our first try 1162 * at sending an INQUIRY. If the device 1163 * has more information to give, 1164 * perform a second request specifying 1165 * the amount of information the device 1166 * is willing to give. 1167 */ 1168 len = inq_buf->additional_length 1169 + offsetof(struct scsi_inquiry_data, 1170 additional_length) + 1; 1171 if (softc->action == PROBE_INQUIRY 1172 && len > SHORT_INQUIRY_LENGTH) { 1173 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY); 1174 xpt_release_ccb(done_ccb); 1175 xpt_schedule(periph, priority); 1176 goto out; 1177 } 1178 1179 scsi_find_quirk(path->device); 1180 1181 scsi_devise_transport(path); 1182 1183 if (path->device->lun_id == 0 && 1184 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 && 1185 (SCSI_QUIRK(path->device)->quirks & 1186 CAM_QUIRK_NORPTLUNS) == 0) { 1187 PROBE_SET_ACTION(softc, 1188 PROBE_REPORT_LUNS); 1189 /* 1190 * Start with room for *one* lun. 1191 */ 1192 periph->path->target->rpl_size = 16; 1193 } else if (INQ_DATA_TQ_ENABLED(inq_buf)) 1194 PROBE_SET_ACTION(softc, 1195 PROBE_MODE_SENSE); 1196 else 1197 PROBE_SET_ACTION(softc, 1198 PROBE_SUPPORTED_VPD_LIST); 1199 1200 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1201 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1202 xpt_acquire_device(path->device); 1203 } 1204 xpt_release_ccb(done_ccb); 1205 xpt_schedule(periph, priority); 1206 goto out; 1207 } else if (path->device->lun_id == 0 && 1208 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 && 1209 (SCSI_QUIRK(path->device)->quirks & 1210 CAM_QUIRK_NORPTLUNS) == 0) { 1211 if (path->device->flags & 1212 CAM_DEV_UNCONFIGURED) { 1213 path->device->flags &= 1214 ~CAM_DEV_UNCONFIGURED; 1215 xpt_acquire_device(path->device); 1216 } 1217 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS); 1218 periph->path->target->rpl_size = 16; 1219 xpt_release_ccb(done_ccb); 1220 xpt_schedule(periph, priority); 1221 goto out; 1222 } 1223 } else if (cam_periph_error(done_ccb, 0, 1224 done_ccb->ccb_h.target_lun > 0 1225 ? SF_RETRY_UA|SF_QUIET_IR 1226 : SF_RETRY_UA, 1227 &softc->saved_ccb) == ERESTART) { 1228 goto out; 1229 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1230 /* Don't wedge the queue */ 1231 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1232 /*run_queue*/TRUE); 1233 } 1234 /* 1235 * If we get to this point, we got an error status back 1236 * from the inquiry and the error status doesn't require 1237 * automatically retrying the command. Therefore, the 1238 * inquiry failed. If we had inquiry information before 1239 * for this device, but this latest inquiry command failed, 1240 * the device has probably gone away. If this device isn't 1241 * already marked unconfigured, notify the peripheral 1242 * drivers that this device is no more. 1243 */ 1244 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 1245 /* Send the async notification. */ 1246 xpt_async(AC_LOST_DEVICE, path, NULL); 1247 PROBE_SET_ACTION(softc, PROBE_INVALID); 1248 1249 xpt_release_ccb(done_ccb); 1250 break; 1251 } 1252 case PROBE_REPORT_LUNS: 1253 { 1254 struct ccb_scsiio *csio; 1255 struct scsi_report_luns_data *lp; 1256 u_int nlun, maxlun; 1257 1258 csio = &done_ccb->csio; 1259 1260 lp = (struct scsi_report_luns_data *)csio->data_ptr; 1261 nlun = scsi_4btoul(lp->length) / 8; 1262 maxlun = (csio->dxfer_len / 8) - 1; 1263 1264 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1265 if (cam_periph_error(done_ccb, 0, 1266 done_ccb->ccb_h.target_lun > 0 ? 1267 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA, 1268 &softc->saved_ccb) == ERESTART) { 1269 goto out; 1270 } 1271 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1272 xpt_release_devq(done_ccb->ccb_h.path, 1, 1273 TRUE); 1274 } 1275 free(lp, M_CAMXPT); 1276 lp = NULL; 1277 } else if (nlun > maxlun) { 1278 /* 1279 * Reallocate and retry to cover all luns 1280 */ 1281 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1282 ("Probe: reallocating REPORT_LUNS for %u luns\n", 1283 nlun)); 1284 free(lp, M_CAMXPT); 1285 path->target->rpl_size = (nlun << 3) + 8; 1286 xpt_release_ccb(done_ccb); 1287 xpt_schedule(periph, priority); 1288 goto out; 1289 } else if (nlun == 0) { 1290 /* 1291 * If there don't appear to be any luns, bail. 1292 */ 1293 free(lp, M_CAMXPT); 1294 lp = NULL; 1295 } else if (probe_strange_rpl_data(lp, maxlun)) { 1296 /* 1297 * If we can't understand the lun format 1298 * of any entry, bail. 1299 */ 1300 free(lp, M_CAMXPT); 1301 lp = NULL; 1302 } else { 1303 lun_id_t lun; 1304 int idx; 1305 1306 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1307 ("Probe: %u lun(s) reported\n", nlun)); 1308 1309 CAM_GET_SIMPLE_LUN(lp, 0, lun); 1310 /* 1311 * If the first lun is not lun 0, then either there 1312 * is no lun 0 in the list, or the list is unsorted. 1313 */ 1314 if (lun != 0) { 1315 for (idx = 0; idx < nlun; idx++) { 1316 CAM_GET_SIMPLE_LUN(lp, idx, lun); 1317 if (lun == 0) { 1318 break; 1319 } 1320 } 1321 if (idx != nlun) { 1322 uint8_t tlun[8]; 1323 memcpy(tlun, 1324 lp->luns[0].lundata, 8); 1325 memcpy(lp->luns[0].lundata, 1326 lp->luns[idx].lundata, 8); 1327 memcpy(lp->luns[idx].lundata, 1328 tlun, 8); 1329 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1330 ("lun 0 in position %u\n", idx)); 1331 } else { 1332 /* 1333 * There is no lun 0 in our list. Destroy 1334 * the validity of the inquiry data so we 1335 * bail here and now. 1336 */ 1337 path->device->flags &= 1338 ~CAM_DEV_INQUIRY_DATA_VALID; 1339 } 1340 } 1341 /* 1342 * If we have an old lun list, We can either 1343 * retest luns that appear to have been dropped, 1344 * or just nuke them. We'll opt for the latter. 1345 * This function will also install the new list 1346 * in the target structure. 1347 */ 1348 probe_purge_old(path, lp); 1349 lp = NULL; 1350 } 1351 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) { 1352 struct scsi_inquiry_data *inq_buf; 1353 inq_buf = &path->device->inq_data; 1354 if (INQ_DATA_TQ_ENABLED(inq_buf)) 1355 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); 1356 else 1357 PROBE_SET_ACTION(softc, 1358 PROBE_SUPPORTED_VPD_LIST); 1359 xpt_release_ccb(done_ccb); 1360 xpt_schedule(periph, priority); 1361 goto out; 1362 } 1363 if (lp) { 1364 free(lp, M_CAMXPT); 1365 } 1366 break; 1367 } 1368 case PROBE_MODE_SENSE: 1369 { 1370 struct ccb_scsiio *csio; 1371 struct scsi_mode_header_6 *mode_hdr; 1372 1373 csio = &done_ccb->csio; 1374 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr; 1375 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1376 struct scsi_control_page *page; 1377 u_int8_t *offset; 1378 1379 offset = ((u_int8_t *)&mode_hdr[1]) 1380 + mode_hdr->blk_desc_len; 1381 page = (struct scsi_control_page *)offset; 1382 path->device->queue_flags = page->queue_flags; 1383 } else if (cam_periph_error(done_ccb, 0, 1384 SF_RETRY_UA|SF_NO_PRINT, 1385 &softc->saved_ccb) == ERESTART) { 1386 goto out; 1387 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1388 /* Don't wedge the queue */ 1389 xpt_release_devq(done_ccb->ccb_h.path, 1390 /*count*/1, /*run_queue*/TRUE); 1391 } 1392 xpt_release_ccb(done_ccb); 1393 free(mode_hdr, M_CAMXPT); 1394 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); 1395 xpt_schedule(periph, priority); 1396 goto out; 1397 } 1398 case PROBE_SUPPORTED_VPD_LIST: 1399 { 1400 struct ccb_scsiio *csio; 1401 struct scsi_vpd_supported_page_list *page_list; 1402 1403 csio = &done_ccb->csio; 1404 page_list = 1405 (struct scsi_vpd_supported_page_list *)csio->data_ptr; 1406 1407 if (path->device->supported_vpds != NULL) { 1408 free(path->device->supported_vpds, M_CAMXPT); 1409 path->device->supported_vpds = NULL; 1410 path->device->supported_vpds_len = 0; 1411 } 1412 1413 if (page_list == NULL) { 1414 /* 1415 * Don't process the command as it was never sent 1416 */ 1417 } else if (CCB_COMPLETED_OK(csio->ccb_h)) { 1418 /* Got vpd list */ 1419 path->device->supported_vpds_len = page_list->length + 1420 SVPD_SUPPORTED_PAGES_HDR_LEN; 1421 path->device->supported_vpds = (uint8_t *)page_list; 1422 xpt_release_ccb(done_ccb); 1423 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID); 1424 xpt_schedule(periph, priority); 1425 goto out; 1426 } else if (cam_periph_error(done_ccb, 0, 1427 SF_RETRY_UA|SF_NO_PRINT, 1428 &softc->saved_ccb) == ERESTART) { 1429 goto out; 1430 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1431 /* Don't wedge the queue */ 1432 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1433 /*run_queue*/TRUE); 1434 } 1435 1436 if (page_list) 1437 free(page_list, M_CAMXPT); 1438 /* No VPDs available, skip to device check. */ 1439 csio->data_ptr = NULL; 1440 goto probe_device_check; 1441 } 1442 case PROBE_DEVICE_ID: 1443 { 1444 struct scsi_vpd_device_id *devid; 1445 struct ccb_scsiio *csio; 1446 uint32_t length = 0; 1447 1448 csio = &done_ccb->csio; 1449 devid = (struct scsi_vpd_device_id *)csio->data_ptr; 1450 1451 /* Clean up from previous instance of this device */ 1452 if (path->device->device_id != NULL) { 1453 path->device->device_id_len = 0; 1454 free(path->device->device_id, M_CAMXPT); 1455 path->device->device_id = NULL; 1456 } 1457 1458 if (devid == NULL) { 1459 /* Don't process the command as it was never sent */ 1460 } else if (CCB_COMPLETED_OK(csio->ccb_h)) { 1461 length = scsi_2btoul(devid->length); 1462 if (length != 0) { 1463 /* 1464 * NB: device_id_len is actual response 1465 * size, not buffer size. 1466 */ 1467 path->device->device_id_len = length + 1468 SVPD_DEVICE_ID_HDR_LEN; 1469 path->device->device_id = (uint8_t *)devid; 1470 } 1471 } else if (cam_periph_error(done_ccb, 0, 1472 SF_RETRY_UA, 1473 &softc->saved_ccb) == ERESTART) { 1474 goto out; 1475 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1476 /* Don't wedge the queue */ 1477 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1478 /*run_queue*/TRUE); 1479 } 1480 1481 /* Free the device id space if we don't use it */ 1482 if (devid && length == 0) 1483 free(devid, M_CAMXPT); 1484 xpt_release_ccb(done_ccb); 1485 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM); 1486 xpt_schedule(periph, priority); 1487 goto out; 1488 } 1489 1490probe_device_check: 1491 case PROBE_SERIAL_NUM: 1492 { 1493 struct ccb_scsiio *csio; 1494 struct scsi_vpd_unit_serial_number *serial_buf; 1495 u_int32_t priority; 1496 int changed; 1497 int have_serialnum; 1498 1499 changed = 1; 1500 have_serialnum = 0; 1501 csio = &done_ccb->csio; 1502 priority = done_ccb->ccb_h.pinfo.priority; 1503 serial_buf = 1504 (struct scsi_vpd_unit_serial_number *)csio->data_ptr; 1505 1506 if (serial_buf == NULL) { 1507 /* 1508 * Don't process the command as it was never sent 1509 */ 1510 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP 1511 && (serial_buf->length > 0)) { 1512 1513 have_serialnum = 1; 1514 path->device->serial_num = 1515 (u_int8_t *)malloc((serial_buf->length + 1), 1516 M_CAMXPT, M_NOWAIT); 1517 if (path->device->serial_num != NULL) { 1518 memcpy(path->device->serial_num, 1519 serial_buf->serial_num, 1520 serial_buf->length); 1521 path->device->serial_num_len = 1522 serial_buf->length; 1523 path->device->serial_num[serial_buf->length] 1524 = '\0'; 1525 } 1526 } else if (cam_periph_error(done_ccb, 0, 1527 SF_RETRY_UA|SF_NO_PRINT, 1528 &softc->saved_ccb) == ERESTART) { 1529 goto out; 1530 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1531 /* Don't wedge the queue */ 1532 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1533 /*run_queue*/TRUE); 1534 } 1535 1536 /* 1537 * Let's see if we have seen this device before. 1538 */ 1539 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) { 1540 MD5_CTX context; 1541 u_int8_t digest[16]; 1542 1543 MD5Init(&context); 1544 1545 MD5Update(&context, 1546 (unsigned char *)&path->device->inq_data, 1547 sizeof(struct scsi_inquiry_data)); 1548 1549 if (have_serialnum) 1550 MD5Update(&context, serial_buf->serial_num, 1551 serial_buf->length); 1552 1553 MD5Final(digest, &context); 1554 if (bcmp(softc->digest, digest, 16) == 0) 1555 changed = 0; 1556 1557 /* 1558 * XXX Do we need to do a TUR in order to ensure 1559 * that the device really hasn't changed??? 1560 */ 1561 if ((changed != 0) 1562 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0)) 1563 xpt_async(AC_LOST_DEVICE, path, NULL); 1564 } 1565 if (serial_buf != NULL) 1566 free(serial_buf, M_CAMXPT); 1567 1568 if (changed != 0) { 1569 /* 1570 * Now that we have all the necessary 1571 * information to safely perform transfer 1572 * negotiations... Controllers don't perform 1573 * any negotiation or tagged queuing until 1574 * after the first XPT_SET_TRAN_SETTINGS ccb is 1575 * received. So, on a new device, just retrieve 1576 * the user settings, and set them as the current 1577 * settings to set the device up. 1578 */ 1579 proberequestdefaultnegotiation(periph); 1580 xpt_release_ccb(done_ccb); 1581 1582 /* 1583 * Perform a TUR to allow the controller to 1584 * perform any necessary transfer negotiation. 1585 */ 1586 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); 1587 xpt_schedule(periph, priority); 1588 goto out; 1589 } 1590 xpt_release_ccb(done_ccb); 1591 break; 1592 } 1593 case PROBE_TUR_FOR_NEGOTIATION: 1594 case PROBE_DV_EXIT: 1595 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1596 cam_periph_error(done_ccb, 0, 1597 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); 1598 } 1599 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1600 /* Don't wedge the queue */ 1601 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1602 /*run_queue*/TRUE); 1603 } 1604 /* 1605 * Do Domain Validation for lun 0 on devices that claim 1606 * to support Synchronous Transfer modes. 1607 */ 1608 if (softc->action == PROBE_TUR_FOR_NEGOTIATION 1609 && done_ccb->ccb_h.target_lun == 0 1610 && (path->device->inq_data.flags & SID_Sync) != 0 1611 && (path->device->flags & CAM_DEV_IN_DV) == 0) { 1612 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1613 ("Begin Domain Validation\n")); 1614 path->device->flags |= CAM_DEV_IN_DV; 1615 xpt_release_ccb(done_ccb); 1616 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1); 1617 xpt_schedule(periph, priority); 1618 goto out; 1619 } 1620 if (softc->action == PROBE_DV_EXIT) { 1621 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1622 ("Leave Domain Validation\n")); 1623 } 1624 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1625 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1626 xpt_acquire_device(path->device); 1627 } 1628 path->device->flags &= 1629 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); 1630 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { 1631 /* Inform the XPT that a new device has been found */ 1632 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 1633 xpt_action(done_ccb); 1634 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 1635 done_ccb); 1636 } 1637 PROBE_SET_ACTION(softc, PROBE_DONE); 1638 xpt_release_ccb(done_ccb); 1639 break; 1640 case PROBE_INQUIRY_BASIC_DV1: 1641 case PROBE_INQUIRY_BASIC_DV2: 1642 { 1643 struct scsi_inquiry_data *nbuf; 1644 struct ccb_scsiio *csio; 1645 1646 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1647 cam_periph_error(done_ccb, 0, 1648 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); 1649 } 1650 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1651 /* Don't wedge the queue */ 1652 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1653 /*run_queue*/TRUE); 1654 } 1655 csio = &done_ccb->csio; 1656 nbuf = (struct scsi_inquiry_data *)csio->data_ptr; 1657 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) { 1658 xpt_print(path, 1659 "inquiry data fails comparison at DV%d step\n", 1660 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2); 1661 if (proberequestbackoff(periph, path->device)) { 1662 path->device->flags &= ~CAM_DEV_IN_DV; 1663 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); 1664 } else { 1665 /* give up */ 1666 PROBE_SET_ACTION(softc, PROBE_DV_EXIT); 1667 } 1668 free(nbuf, M_CAMXPT); 1669 xpt_release_ccb(done_ccb); 1670 xpt_schedule(periph, priority); 1671 goto out; 1672 } 1673 free(nbuf, M_CAMXPT); 1674 if (softc->action == PROBE_INQUIRY_BASIC_DV1) { 1675 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2); 1676 xpt_release_ccb(done_ccb); 1677 xpt_schedule(periph, priority); 1678 goto out; 1679 } 1680 if (softc->action == PROBE_INQUIRY_BASIC_DV2) { 1681 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1682 ("Leave Domain Validation Successfully\n")); 1683 } 1684 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1685 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1686 xpt_acquire_device(path->device); 1687 } 1688 path->device->flags &= 1689 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); 1690 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { 1691 /* Inform the XPT that a new device has been found */ 1692 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 1693 xpt_action(done_ccb); 1694 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 1695 done_ccb); 1696 } 1697 PROBE_SET_ACTION(softc, PROBE_DONE); 1698 xpt_release_ccb(done_ccb); 1699 break; 1700 } 1701 default: 1702 panic("probedone: invalid action state 0x%x\n", softc->action); 1703 } 1704 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 1705 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); 1706 done_ccb->ccb_h.status = CAM_REQ_CMP; 1707 xpt_done(done_ccb); 1708 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { 1709 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n")); 1710 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */ 1711 cam_release_devq(path, 0, 0, 0, FALSE); 1712 cam_periph_invalidate(periph); 1713 cam_periph_release_locked(periph); 1714 } else { 1715 probeschedule(periph); 1716 goto out; 1717 } 1718} 1719 1720static int 1721probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun) 1722{ 1723 uint32_t idx; 1724 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8)); 1725 1726 for (idx = 0; idx < nlun; idx++) { 1727 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) { 1728 return (-1); 1729 } 1730 } 1731 return (0); 1732} 1733 1734static void 1735probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new) 1736{ 1737 struct cam_path *tp; 1738 struct scsi_report_luns_data *old; 1739 u_int idx1, idx2, nlun_old, nlun_new, this_lun; 1740 u_int8_t *ol, *nl; 1741 1742 if (path->target == NULL) { 1743 return; 1744 } 1745 if (path->target->luns == NULL) { 1746 path->target->luns = new; 1747 return; 1748 } 1749 old = path->target->luns; 1750 nlun_old = scsi_4btoul(old->length) / 8; 1751 nlun_new = scsi_4btoul(new->length) / 8; 1752 1753 /* 1754 * We are not going to assume sorted lists. Deal. 1755 */ 1756 for (idx1 = 0; idx1 < nlun_old; idx1++) { 1757 ol = old->luns[idx1].lundata; 1758 for (idx2 = 0; idx2 < nlun_new; idx2++) { 1759 nl = new->luns[idx2].lundata; 1760 if (memcmp(nl, ol, 8) == 0) { 1761 break; 1762 } 1763 } 1764 if (idx2 < nlun_new) { 1765 continue; 1766 } 1767 /* 1768 * An 'old' item not in the 'new' list. 1769 * Nuke it. Except that if it is lun 0, 1770 * that would be what the probe state 1771 * machine is currently working on, 1772 * so we won't do that. 1773 * 1774 * We also cannot nuke it if it is 1775 * not in a lun format we understand. 1776 */ 1777 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) { 1778 continue; 1779 } 1780 CAM_GET_SIMPLE_LUN(old, idx1, this_lun); 1781 if (this_lun == 0) { 1782 continue; 1783 } 1784 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path), 1785 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) { 1786 xpt_async(AC_LOST_DEVICE, tp, NULL); 1787 xpt_free_path(tp); 1788 } 1789 } 1790 free(old, M_CAMXPT); 1791 path->target->luns = new; 1792} 1793 1794static void 1795probecleanup(struct cam_periph *periph) 1796{ 1797 free(periph->softc, M_CAMXPT); 1798} 1799 1800static void 1801scsi_find_quirk(struct cam_ed *device) 1802{ 1803 struct scsi_quirk_entry *quirk; 1804 caddr_t match; 1805 1806 match = cam_quirkmatch((caddr_t)&device->inq_data, 1807 (caddr_t)scsi_quirk_table, 1808 sizeof(scsi_quirk_table) / 1809 sizeof(*scsi_quirk_table), 1810 sizeof(*scsi_quirk_table), scsi_inquiry_match); 1811 1812 if (match == NULL) 1813 panic("xpt_find_quirk: device didn't match wildcard entry!!"); 1814 1815 quirk = (struct scsi_quirk_entry *)match; 1816 device->quirk = quirk; 1817 device->mintags = quirk->mintags; 1818 device->maxtags = quirk->maxtags; 1819} 1820 1821static int 1822sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS) 1823{ 1824 int error, val; 1825 1826 val = cam_srch_hi; 1827 error = sysctl_handle_int(oidp, &val, 0, req); 1828 if (error != 0 || req->newptr == NULL) 1829 return (error); 1830 if (val == 0 || val == 1) { 1831 cam_srch_hi = val; 1832 return (0); 1833 } else { 1834 return (EINVAL); 1835 } 1836} 1837 1838typedef struct { 1839 union ccb *request_ccb; 1840 struct ccb_pathinq *cpi; 1841 int counter; 1842 int lunindex[0]; 1843} scsi_scan_bus_info; 1844 1845/* 1846 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. 1847 * As the scan progresses, scsi_scan_bus is used as the 1848 * callback on completion function. 1849 */ 1850static void 1851scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) 1852{ 1853 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1854 ("scsi_scan_bus\n")); 1855 switch (request_ccb->ccb_h.func_code) { 1856 case XPT_SCAN_BUS: 1857 case XPT_SCAN_TGT: 1858 { 1859 scsi_scan_bus_info *scan_info; 1860 union ccb *work_ccb, *reset_ccb; 1861 struct cam_path *path; 1862 u_int i; 1863 u_int low_target, max_target; 1864 u_int initiator_id; 1865 1866 /* Find out the characteristics of the bus */ 1867 work_ccb = xpt_alloc_ccb_nowait(); 1868 if (work_ccb == NULL) { 1869 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 1870 xpt_done(request_ccb); 1871 return; 1872 } 1873 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path, 1874 request_ccb->ccb_h.pinfo.priority); 1875 work_ccb->ccb_h.func_code = XPT_PATH_INQ; 1876 xpt_action(work_ccb); 1877 if (work_ccb->ccb_h.status != CAM_REQ_CMP) { 1878 request_ccb->ccb_h.status = work_ccb->ccb_h.status; 1879 xpt_free_ccb(work_ccb); 1880 xpt_done(request_ccb); 1881 return; 1882 } 1883 1884 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) { 1885 /* 1886 * Can't scan the bus on an adapter that 1887 * cannot perform the initiator role. 1888 */ 1889 request_ccb->ccb_h.status = CAM_REQ_CMP; 1890 xpt_free_ccb(work_ccb); 1891 xpt_done(request_ccb); 1892 return; 1893 } 1894 1895 /* We may need to reset bus first, if we haven't done it yet. */ 1896 if ((work_ccb->cpi.hba_inquiry & 1897 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) && 1898 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) && 1899 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) { 1900 reset_ccb = xpt_alloc_ccb_nowait(); 1901 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path, 1902 CAM_PRIORITY_NONE); 1903 reset_ccb->ccb_h.func_code = XPT_RESET_BUS; 1904 xpt_action(reset_ccb); 1905 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) { 1906 request_ccb->ccb_h.status = reset_ccb->ccb_h.status; 1907 xpt_free_ccb(reset_ccb); 1908 xpt_free_ccb(work_ccb); 1909 xpt_done(request_ccb); 1910 return; 1911 } 1912 xpt_free_ccb(reset_ccb); 1913 } 1914 1915 /* Save some state for use while we probe for devices */ 1916 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) + 1917 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT); 1918 if (scan_info == NULL) { 1919 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 1920 xpt_done(request_ccb); 1921 return; 1922 } 1923 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1924 ("SCAN start for %p\n", scan_info)); 1925 scan_info->request_ccb = request_ccb; 1926 scan_info->cpi = &work_ccb->cpi; 1927 1928 /* Cache on our stack so we can work asynchronously */ 1929 max_target = scan_info->cpi->max_target; 1930 low_target = 0; 1931 initiator_id = scan_info->cpi->initiator_id; 1932 1933 1934 /* 1935 * We can scan all targets in parallel, or do it sequentially. 1936 */ 1937 1938 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) { 1939 max_target = low_target = request_ccb->ccb_h.target_id; 1940 scan_info->counter = 0; 1941 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) { 1942 max_target = 0; 1943 scan_info->counter = 0; 1944 } else { 1945 scan_info->counter = scan_info->cpi->max_target + 1; 1946 if (scan_info->cpi->initiator_id < scan_info->counter) { 1947 scan_info->counter--; 1948 } 1949 } 1950 1951 for (i = low_target; i <= max_target; i++) { 1952 cam_status status; 1953 if (i == initiator_id) 1954 continue; 1955
| 32 33#include <sys/param.h> 34#include <sys/bus.h> 35#include <sys/systm.h> 36#include <sys/types.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/time.h> 40#include <sys/conf.h> 41#include <sys/fcntl.h> 42#include <sys/md5.h> 43#include <sys/interrupt.h> 44#include <sys/sbuf.h> 45 46#include <sys/lock.h> 47#include <sys/mutex.h> 48#include <sys/sysctl.h> 49 50#include <cam/cam.h> 51#include <cam/cam_ccb.h> 52#include <cam/cam_queue.h> 53#include <cam/cam_periph.h> 54#include <cam/cam_sim.h> 55#include <cam/cam_xpt.h> 56#include <cam/cam_xpt_sim.h> 57#include <cam/cam_xpt_periph.h> 58#include <cam/cam_xpt_internal.h> 59#include <cam/cam_debug.h> 60 61#include <cam/scsi/scsi_all.h> 62#include <cam/scsi/scsi_message.h> 63#include <cam/scsi/scsi_pass.h> 64#include <machine/stdarg.h> /* for xpt_print below */ 65#include "opt_cam.h" 66 67struct scsi_quirk_entry { 68 struct scsi_inquiry_pattern inq_pat; 69 u_int8_t quirks; 70#define CAM_QUIRK_NOLUNS 0x01 71#define CAM_QUIRK_NOVPDS 0x02 72#define CAM_QUIRK_HILUNS 0x04 73#define CAM_QUIRK_NOHILUNS 0x08 74#define CAM_QUIRK_NORPTLUNS 0x10 75 u_int mintags; 76 u_int maxtags; 77}; 78#define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk)) 79 80static int cam_srch_hi = 0; 81TUNABLE_INT("kern.cam.cam_srch_hi", &cam_srch_hi); 82static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS); 83SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT|CTLFLAG_RW, 0, 0, 84 sysctl_cam_search_luns, "I", 85 "allow search above LUN 7 for SCSI3 and greater devices"); 86 87#define CAM_SCSI2_MAXLUN 8 88#define CAM_CAN_GET_SIMPLE_LUN(x, i) \ 89 ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 90 RPL_LUNDATA_ATYP_PERIPH) || \ 91 (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 92 RPL_LUNDATA_ATYP_FLAT)) 93#define CAM_GET_SIMPLE_LUN(lp, i, lval) \ 94 if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ 95 RPL_LUNDATA_ATYP_PERIPH) { \ 96 (lval) = (lp)->luns[(i)].lundata[1]; \ 97 } else { \ 98 (lval) = (lp)->luns[(i)].lundata[0]; \ 99 (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \ 100 (lval) <<= 8; \ 101 (lval) |= (lp)->luns[(i)].lundata[1]; \ 102 } 103/* 104 * If we're not quirked to search <= the first 8 luns 105 * and we are either quirked to search above lun 8, 106 * or we're > SCSI-2 and we've enabled hilun searching, 107 * or we're > SCSI-2 and the last lun was a success, 108 * we can look for luns above lun 8. 109 */ 110#define CAN_SRCH_HI_SPARSE(dv) \ 111 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ 112 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ 113 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi))) 114 115#define CAN_SRCH_HI_DENSE(dv) \ 116 (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ 117 && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ 118 || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2))) 119 120static periph_init_t probe_periph_init; 121 122static struct periph_driver probe_driver = 123{ 124 probe_periph_init, "probe", 125 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0, 126 CAM_PERIPH_DRV_EARLY 127}; 128 129PERIPHDRIVER_DECLARE(probe, probe_driver); 130 131typedef enum { 132 PROBE_TUR, 133 PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */ 134 PROBE_FULL_INQUIRY, 135 PROBE_REPORT_LUNS, 136 PROBE_MODE_SENSE, 137 PROBE_SUPPORTED_VPD_LIST, 138 PROBE_DEVICE_ID, 139 PROBE_SERIAL_NUM, 140 PROBE_TUR_FOR_NEGOTIATION, 141 PROBE_INQUIRY_BASIC_DV1, 142 PROBE_INQUIRY_BASIC_DV2, 143 PROBE_DV_EXIT, 144 PROBE_DONE, 145 PROBE_INVALID 146} probe_action; 147 148static char *probe_action_text[] = { 149 "PROBE_TUR", 150 "PROBE_INQUIRY", 151 "PROBE_FULL_INQUIRY", 152 "PROBE_REPORT_LUNS", 153 "PROBE_MODE_SENSE", 154 "PROBE_SUPPORTED_VPD_LIST", 155 "PROBE_DEVICE_ID", 156 "PROBE_SERIAL_NUM", 157 "PROBE_TUR_FOR_NEGOTIATION", 158 "PROBE_INQUIRY_BASIC_DV1", 159 "PROBE_INQUIRY_BASIC_DV2", 160 "PROBE_DV_EXIT", 161 "PROBE_DONE", 162 "PROBE_INVALID" 163}; 164 165#define PROBE_SET_ACTION(softc, newaction) \ 166do { \ 167 char **text; \ 168 text = probe_action_text; \ 169 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \ 170 ("Probe %s to %s\n", text[(softc)->action], \ 171 text[(newaction)])); \ 172 (softc)->action = (newaction); \ 173} while(0) 174 175typedef enum { 176 PROBE_INQUIRY_CKSUM = 0x01, 177 PROBE_SERIAL_CKSUM = 0x02, 178 PROBE_NO_ANNOUNCE = 0x04 179} probe_flags; 180 181typedef struct { 182 TAILQ_HEAD(, ccb_hdr) request_ccbs; 183 probe_action action; 184 union ccb saved_ccb; 185 probe_flags flags; 186 MD5_CTX context; 187 u_int8_t digest[16]; 188 struct cam_periph *periph; 189} probe_softc; 190 191static const char quantum[] = "QUANTUM"; 192static const char sony[] = "SONY"; 193static const char west_digital[] = "WDIGTL"; 194static const char samsung[] = "SAMSUNG"; 195static const char seagate[] = "SEAGATE"; 196static const char microp[] = "MICROP"; 197 198static struct scsi_quirk_entry scsi_quirk_table[] = 199{ 200 { 201 /* Reports QUEUE FULL for temporary resource shortages */ 202 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" }, 203 /*quirks*/0, /*mintags*/24, /*maxtags*/32 204 }, 205 { 206 /* Reports QUEUE FULL for temporary resource shortages */ 207 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" }, 208 /*quirks*/0, /*mintags*/24, /*maxtags*/32 209 }, 210 { 211 /* Reports QUEUE FULL for temporary resource shortages */ 212 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" }, 213 /*quirks*/0, /*mintags*/24, /*maxtags*/32 214 }, 215 { 216 /* Broken tagged queuing drive */ 217 { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" }, 218 /*quirks*/0, /*mintags*/0, /*maxtags*/0 219 }, 220 { 221 /* Broken tagged queuing drive */ 222 { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" }, 223 /*quirks*/0, /*mintags*/0, /*maxtags*/0 224 }, 225 { 226 /* Broken tagged queuing drive */ 227 { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" }, 228 /*quirks*/0, /*mintags*/0, /*maxtags*/0 229 }, 230 { 231 /* 232 * Unfortunately, the Quantum Atlas III has the same 233 * problem as the Atlas II drives above. 234 * Reported by: "Johan Granlund" <johan@granlund.nu> 235 * 236 * For future reference, the drive with the problem was: 237 * QUANTUM QM39100TD-SW N1B0 238 * 239 * It's possible that Quantum will fix the problem in later 240 * firmware revisions. If that happens, the quirk entry 241 * will need to be made specific to the firmware revisions 242 * with the problem. 243 * 244 */ 245 /* Reports QUEUE FULL for temporary resource shortages */ 246 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" }, 247 /*quirks*/0, /*mintags*/24, /*maxtags*/32 248 }, 249 { 250 /* 251 * 18 Gig Atlas III, same problem as the 9G version. 252 * Reported by: Andre Albsmeier 253 * <andre.albsmeier@mchp.siemens.de> 254 * 255 * For future reference, the drive with the problem was: 256 * QUANTUM QM318000TD-S N491 257 */ 258 /* Reports QUEUE FULL for temporary resource shortages */ 259 { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" }, 260 /*quirks*/0, /*mintags*/24, /*maxtags*/32 261 }, 262 { 263 /* 264 * Broken tagged queuing drive 265 * Reported by: Bret Ford <bford@uop.cs.uop.edu> 266 * and: Martin Renters <martin@tdc.on.ca> 267 */ 268 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" }, 269 /*quirks*/0, /*mintags*/0, /*maxtags*/0 270 }, 271 /* 272 * The Seagate Medalist Pro drives have very poor write 273 * performance with anything more than 2 tags. 274 * 275 * Reported by: Paul van der Zwan <paulz@trantor.xs4all.nl> 276 * Drive: <SEAGATE ST36530N 1444> 277 * 278 * Reported by: Jeremy Lea <reg@shale.csir.co.za> 279 * Drive: <SEAGATE ST34520W 1281> 280 * 281 * No one has actually reported that the 9G version 282 * (ST39140*) of the Medalist Pro has the same problem, but 283 * we're assuming that it does because the 4G and 6.5G 284 * versions of the drive are broken. 285 */ 286 { 287 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"}, 288 /*quirks*/0, /*mintags*/2, /*maxtags*/2 289 }, 290 { 291 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"}, 292 /*quirks*/0, /*mintags*/2, /*maxtags*/2 293 }, 294 { 295 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"}, 296 /*quirks*/0, /*mintags*/2, /*maxtags*/2 297 }, 298 { 299 /* 300 * Experiences command timeouts under load with a 301 * tag count higher than 55. 302 */ 303 { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"}, 304 /*quirks*/0, /*mintags*/2, /*maxtags*/55 305 }, 306 { 307 /* 308 * Slow when tagged queueing is enabled. Write performance 309 * steadily drops off with more and more concurrent 310 * transactions. Best sequential write performance with 311 * tagged queueing turned off and write caching turned on. 312 * 313 * PR: kern/10398 314 * Submitted by: Hideaki Okada <hokada@isl.melco.co.jp> 315 * Drive: DCAS-34330 w/ "S65A" firmware. 316 * 317 * The drive with the problem had the "S65A" firmware 318 * revision, and has also been reported (by Stephen J. 319 * Roznowski <sjr@home.net>) for a drive with the "S61A" 320 * firmware revision. 321 * 322 * Although no one has reported problems with the 2 gig 323 * version of the DCAS drive, the assumption is that it 324 * has the same problems as the 4 gig version. Therefore 325 * this quirk entries disables tagged queueing for all 326 * DCAS drives. 327 */ 328 { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" }, 329 /*quirks*/0, /*mintags*/0, /*maxtags*/0 330 }, 331 { 332 /* Broken tagged queuing drive */ 333 { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" }, 334 /*quirks*/0, /*mintags*/0, /*maxtags*/0 335 }, 336 { 337 /* Broken tagged queuing drive */ 338 { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" }, 339 /*quirks*/0, /*mintags*/0, /*maxtags*/0 340 }, 341 { 342 /* This does not support other than LUN 0 */ 343 { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" }, 344 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 345 }, 346 { 347 /* 348 * Broken tagged queuing drive. 349 * Submitted by: 350 * NAKAJI Hiroyuki <nakaji@zeisei.dpri.kyoto-u.ac.jp> 351 * in PR kern/9535 352 */ 353 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" }, 354 /*quirks*/0, /*mintags*/0, /*maxtags*/0 355 }, 356 { 357 /* 358 * Slow when tagged queueing is enabled. (1.5MB/sec versus 359 * 8MB/sec.) 360 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu> 361 * Best performance with these drives is achieved with 362 * tagged queueing turned off, and write caching turned on. 363 */ 364 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" }, 365 /*quirks*/0, /*mintags*/0, /*maxtags*/0 366 }, 367 { 368 /* 369 * Slow when tagged queueing is enabled. (1.5MB/sec versus 370 * 8MB/sec.) 371 * Submitted by: Andrew Gallatin <gallatin@cs.duke.edu> 372 * Best performance with these drives is achieved with 373 * tagged queueing turned off, and write caching turned on. 374 */ 375 { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" }, 376 /*quirks*/0, /*mintags*/0, /*maxtags*/0 377 }, 378 { 379 /* 380 * Doesn't handle queue full condition correctly, 381 * so we need to limit maxtags to what the device 382 * can handle instead of determining this automatically. 383 */ 384 { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" }, 385 /*quirks*/0, /*mintags*/2, /*maxtags*/32 386 }, 387 { 388 /* Really only one LUN */ 389 { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" }, 390 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 391 }, 392 { 393 /* I can't believe we need a quirk for DPT volumes. */ 394 { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" }, 395 CAM_QUIRK_NOLUNS, 396 /*mintags*/0, /*maxtags*/255 397 }, 398 { 399 /* 400 * Many Sony CDROM drives don't like multi-LUN probing. 401 */ 402 { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" }, 403 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 404 }, 405 { 406 /* 407 * This drive doesn't like multiple LUN probing. 408 * Submitted by: Parag Patel <parag@cgt.com> 409 */ 410 { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" }, 411 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 412 }, 413 { 414 { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" }, 415 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 416 }, 417 { 418 /* 419 * The 8200 doesn't like multi-lun probing, and probably 420 * don't like serial number requests either. 421 */ 422 { 423 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", 424 "EXB-8200*", "*" 425 }, 426 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 427 }, 428 { 429 /* 430 * Let's try the same as above, but for a drive that says 431 * it's an IPL-6860 but is actually an EXB 8200. 432 */ 433 { 434 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", 435 "IPL-6860*", "*" 436 }, 437 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 438 }, 439 { 440 /* 441 * These Hitachi drives don't like multi-lun probing. 442 * The PR submitter has a DK319H, but says that the Linux 443 * kernel has a similar work-around for the DK312 and DK314, 444 * so all DK31* drives are quirked here. 445 * PR: misc/18793 446 * Submitted by: Paul Haddad <paul@pth.com> 447 */ 448 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" }, 449 CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 450 }, 451 { 452 /* 453 * The Hitachi CJ series with J8A8 firmware apparantly has 454 * problems with tagged commands. 455 * PR: 23536 456 * Reported by: amagai@nue.org 457 */ 458 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" }, 459 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 460 }, 461 { 462 /* 463 * These are the large storage arrays. 464 * Submitted by: William Carrel <william.carrel@infospace.com> 465 */ 466 { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" }, 467 CAM_QUIRK_HILUNS, 2, 1024 468 }, 469 { 470 /* 471 * This old revision of the TDC3600 is also SCSI-1, and 472 * hangs upon serial number probing. 473 */ 474 { 475 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG", 476 " TDC 3600", "U07:" 477 }, 478 CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0 479 }, 480 { 481 /* 482 * Would repond to all LUNs if asked for. 483 */ 484 { 485 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER", 486 "CP150", "*" 487 }, 488 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 489 }, 490 { 491 /* 492 * Would repond to all LUNs if asked for. 493 */ 494 { 495 T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY", 496 "96X2*", "*" 497 }, 498 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 499 }, 500 { 501 /* Submitted by: Matthew Dodd <winter@jurai.net> */ 502 { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" }, 503 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 504 }, 505 { 506 /* Submitted by: Matthew Dodd <winter@jurai.net> */ 507 { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" }, 508 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 509 }, 510 { 511 /* TeraSolutions special settings for TRC-22 RAID */ 512 { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" }, 513 /*quirks*/0, /*mintags*/55, /*maxtags*/255 514 }, 515 { 516 /* Veritas Storage Appliance */ 517 { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" }, 518 CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024 519 }, 520 { 521 /* 522 * Would respond to all LUNs. Device type and removable 523 * flag are jumper-selectable. 524 */ 525 { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix", 526 "Tahiti 1", "*" 527 }, 528 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 529 }, 530 { 531 /* EasyRAID E5A aka. areca ARC-6010 */ 532 { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" }, 533 CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255 534 }, 535 { 536 { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" }, 537 CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 538 }, 539 { 540 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" }, 541 CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255 542 }, 543 { 544 /* Default tagged queuing parameters for all devices */ 545 { 546 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, 547 /*vendor*/"*", /*product*/"*", /*revision*/"*" 548 }, 549 /*quirks*/0, /*mintags*/2, /*maxtags*/255 550 }, 551}; 552 553static const int scsi_quirk_table_size = 554 sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table); 555 556static cam_status proberegister(struct cam_periph *periph, 557 void *arg); 558static void probeschedule(struct cam_periph *probe_periph); 559static int device_has_vpd(struct cam_ed *device, uint8_t page_id); 560static void probestart(struct cam_periph *periph, union ccb *start_ccb); 561static void proberequestdefaultnegotiation(struct cam_periph *periph); 562static int proberequestbackoff(struct cam_periph *periph, 563 struct cam_ed *device); 564static void probedone(struct cam_periph *periph, union ccb *done_ccb); 565static int probe_strange_rpl_data(struct scsi_report_luns_data *rp, 566 uint32_t maxlun); 567static void probe_purge_old(struct cam_path *path, 568 struct scsi_report_luns_data *new); 569static void probecleanup(struct cam_periph *periph); 570static void scsi_find_quirk(struct cam_ed *device); 571static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb); 572static void scsi_scan_lun(struct cam_periph *periph, 573 struct cam_path *path, cam_flags flags, 574 union ccb *ccb); 575static void xptscandone(struct cam_periph *periph, union ccb *done_ccb); 576static struct cam_ed * 577 scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, 578 lun_id_t lun_id); 579static void scsi_devise_transport(struct cam_path *path); 580static void scsi_set_transfer_settings(struct ccb_trans_settings *cts, 581 struct cam_ed *device, 582 int async_update); 583static void scsi_toggle_tags(struct cam_path *path); 584static void scsi_dev_async(u_int32_t async_code, 585 struct cam_eb *bus, 586 struct cam_et *target, 587 struct cam_ed *device, 588 void *async_arg); 589static void scsi_action(union ccb *start_ccb); 590static void scsi_announce_periph(struct cam_periph *periph); 591 592static struct xpt_xport scsi_xport = { 593 .alloc_device = scsi_alloc_device, 594 .action = scsi_action, 595 .async = scsi_dev_async, 596 .announce = scsi_announce_periph, 597}; 598 599struct xpt_xport * 600scsi_get_xport(void) 601{ 602 return (&scsi_xport); 603} 604 605static void 606probe_periph_init() 607{ 608} 609 610static cam_status 611proberegister(struct cam_periph *periph, void *arg) 612{ 613 union ccb *request_ccb; /* CCB representing the probe request */ 614 cam_status status; 615 probe_softc *softc; 616 617 request_ccb = (union ccb *)arg; 618 if (request_ccb == NULL) { 619 printf("proberegister: no probe CCB, " 620 "can't register device\n"); 621 return(CAM_REQ_CMP_ERR); 622 } 623 624 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT); 625 626 if (softc == NULL) { 627 printf("proberegister: Unable to probe new device. " 628 "Unable to allocate softc\n"); 629 return(CAM_REQ_CMP_ERR); 630 } 631 TAILQ_INIT(&softc->request_ccbs); 632 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, 633 periph_links.tqe); 634 softc->flags = 0; 635 periph->softc = softc; 636 softc->periph = periph; 637 softc->action = PROBE_INVALID; 638 status = cam_periph_acquire(periph); 639 if (status != CAM_REQ_CMP) { 640 return (status); 641 } 642 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n")); 643 644 /* 645 * Ensure we've waited at least a bus settle 646 * delay before attempting to probe the device. 647 * For HBAs that don't do bus resets, this won't make a difference. 648 */ 649 cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset, 650 scsi_delay); 651 probeschedule(periph); 652 return(CAM_REQ_CMP); 653} 654 655static void 656probeschedule(struct cam_periph *periph) 657{ 658 struct ccb_pathinq cpi; 659 union ccb *ccb; 660 probe_softc *softc; 661 662 softc = (probe_softc *)periph->softc; 663 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 664 665 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE); 666 cpi.ccb_h.func_code = XPT_PATH_INQ; 667 xpt_action((union ccb *)&cpi); 668 669 /* 670 * If a device has gone away and another device, or the same one, 671 * is back in the same place, it should have a unit attention 672 * condition pending. It will not report the unit attention in 673 * response to an inquiry, which may leave invalid transfer 674 * negotiations in effect. The TUR will reveal the unit attention 675 * condition. Only send the TUR for lun 0, since some devices 676 * will get confused by commands other than inquiry to non-existent 677 * luns. If you think a device has gone away start your scan from 678 * lun 0. This will insure that any bogus transfer settings are 679 * invalidated. 680 * 681 * If we haven't seen the device before and the controller supports 682 * some kind of transfer negotiation, negotiate with the first 683 * sent command if no bus reset was performed at startup. This 684 * ensures that the device is not confused by transfer negotiation 685 * settings left over by loader or BIOS action. 686 */ 687 if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 688 && (ccb->ccb_h.target_lun == 0)) { 689 PROBE_SET_ACTION(softc, PROBE_TUR); 690 } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0 691 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) { 692 proberequestdefaultnegotiation(periph); 693 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 694 } else { 695 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 696 } 697 698 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE) 699 softc->flags |= PROBE_NO_ANNOUNCE; 700 else 701 softc->flags &= ~PROBE_NO_ANNOUNCE; 702 703 xpt_schedule(periph, CAM_PRIORITY_XPT); 704} 705 706static int 707device_has_vpd(struct cam_ed *device, uint8_t page_id) 708{ 709 int i, num_pages; 710 struct scsi_vpd_supported_pages *vpds; 711 712 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds; 713 num_pages = device->supported_vpds_len - SVPD_SUPPORTED_PAGES_HDR_LEN; 714 for (i = 0;i < num_pages;i++) 715 if (vpds->page_list[i] == page_id) 716 return 1; 717 718 return 0; 719} 720 721static void 722probestart(struct cam_periph *periph, union ccb *start_ccb) 723{ 724 /* Probe the device that our peripheral driver points to */ 725 struct ccb_scsiio *csio; 726 probe_softc *softc; 727 728 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n")); 729 730 softc = (probe_softc *)periph->softc; 731 csio = &start_ccb->csio; 732again: 733 734 switch (softc->action) { 735 case PROBE_TUR: 736 case PROBE_TUR_FOR_NEGOTIATION: 737 case PROBE_DV_EXIT: 738 { 739 scsi_test_unit_ready(csio, 740 /*retries*/4, 741 probedone, 742 MSG_SIMPLE_Q_TAG, 743 SSD_FULL_SIZE, 744 /*timeout*/60000); 745 break; 746 } 747 case PROBE_INQUIRY: 748 case PROBE_FULL_INQUIRY: 749 case PROBE_INQUIRY_BASIC_DV1: 750 case PROBE_INQUIRY_BASIC_DV2: 751 { 752 u_int inquiry_len; 753 struct scsi_inquiry_data *inq_buf; 754 755 inq_buf = &periph->path->device->inq_data; 756 757 /* 758 * If the device is currently configured, we calculate an 759 * MD5 checksum of the inquiry data, and if the serial number 760 * length is greater than 0, add the serial number data 761 * into the checksum as well. Once the inquiry and the 762 * serial number check finish, we attempt to figure out 763 * whether we still have the same device. 764 */ 765 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { 766 767 MD5Init(&softc->context); 768 MD5Update(&softc->context, (unsigned char *)inq_buf, 769 sizeof(struct scsi_inquiry_data)); 770 softc->flags |= PROBE_INQUIRY_CKSUM; 771 if (periph->path->device->serial_num_len > 0) { 772 MD5Update(&softc->context, 773 periph->path->device->serial_num, 774 periph->path->device->serial_num_len); 775 softc->flags |= PROBE_SERIAL_CKSUM; 776 } 777 MD5Final(softc->digest, &softc->context); 778 } 779 780 if (softc->action == PROBE_INQUIRY) 781 inquiry_len = SHORT_INQUIRY_LENGTH; 782 else 783 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf); 784 785 /* 786 * Some parallel SCSI devices fail to send an 787 * ignore wide residue message when dealing with 788 * odd length inquiry requests. Round up to be 789 * safe. 790 */ 791 inquiry_len = roundup2(inquiry_len, 2); 792 793 if (softc->action == PROBE_INQUIRY_BASIC_DV1 794 || softc->action == PROBE_INQUIRY_BASIC_DV2) { 795 inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT); 796 } 797 if (inq_buf == NULL) { 798 xpt_print(periph->path, "malloc failure- skipping Basic" 799 "Domain Validation\n"); 800 PROBE_SET_ACTION(softc, PROBE_DV_EXIT); 801 scsi_test_unit_ready(csio, 802 /*retries*/4, 803 probedone, 804 MSG_SIMPLE_Q_TAG, 805 SSD_FULL_SIZE, 806 /*timeout*/60000); 807 break; 808 } 809 scsi_inquiry(csio, 810 /*retries*/4, 811 probedone, 812 MSG_SIMPLE_Q_TAG, 813 (u_int8_t *)inq_buf, 814 inquiry_len, 815 /*evpd*/FALSE, 816 /*page_code*/0, 817 SSD_MIN_SIZE, 818 /*timeout*/60 * 1000); 819 break; 820 } 821 case PROBE_REPORT_LUNS: 822 { 823 void *rp; 824 825 rp = malloc(periph->path->target->rpl_size, 826 M_CAMXPT, M_NOWAIT | M_ZERO); 827 if (rp == NULL) { 828 struct scsi_inquiry_data *inq_buf; 829 inq_buf = &periph->path->device->inq_data; 830 xpt_print(periph->path, 831 "Unable to alloc report luns storage\n"); 832 if (INQ_DATA_TQ_ENABLED(inq_buf)) 833 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); 834 else 835 PROBE_SET_ACTION(softc, 836 PROBE_SUPPORTED_VPD_LIST); 837 goto again; 838 } 839 scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG, 840 RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size, 841 SSD_FULL_SIZE, 60000); break; 842 break; 843 } 844 case PROBE_MODE_SENSE: 845 { 846 void *mode_buf; 847 int mode_buf_len; 848 849 mode_buf_len = sizeof(struct scsi_mode_header_6) 850 + sizeof(struct scsi_mode_blk_desc) 851 + sizeof(struct scsi_control_page); 852 mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT); 853 if (mode_buf != NULL) { 854 scsi_mode_sense(csio, 855 /*retries*/4, 856 probedone, 857 MSG_SIMPLE_Q_TAG, 858 /*dbd*/FALSE, 859 SMS_PAGE_CTRL_CURRENT, 860 SMS_CONTROL_MODE_PAGE, 861 mode_buf, 862 mode_buf_len, 863 SSD_FULL_SIZE, 864 /*timeout*/60000); 865 break; 866 } 867 xpt_print(periph->path, "Unable to mode sense control page - " 868 "malloc failure\n"); 869 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); 870 } 871 /* FALLTHROUGH */ 872 case PROBE_SUPPORTED_VPD_LIST: 873 { 874 struct scsi_vpd_supported_page_list *vpd_list; 875 struct cam_ed *device; 876 877 vpd_list = NULL; 878 device = periph->path->device; 879 880 if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0) 881 vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT, 882 M_NOWAIT | M_ZERO); 883 884 if (vpd_list != NULL) { 885 scsi_inquiry(csio, 886 /*retries*/4, 887 probedone, 888 MSG_SIMPLE_Q_TAG, 889 (u_int8_t *)vpd_list, 890 sizeof(*vpd_list), 891 /*evpd*/TRUE, 892 SVPD_SUPPORTED_PAGE_LIST, 893 SSD_MIN_SIZE, 894 /*timeout*/60 * 1000); 895 break; 896 } 897 /* 898 * We'll have to do without, let our probedone 899 * routine finish up for us. 900 */ 901 start_ccb->csio.data_ptr = NULL; 902 probedone(periph, start_ccb); 903 return; 904 } 905 case PROBE_DEVICE_ID: 906 { 907 struct scsi_vpd_device_id *devid; 908 struct cam_ed *device; 909 910 devid = NULL; 911 device = periph->path->device; 912 if (device_has_vpd(device, SVPD_DEVICE_ID)) 913 devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT, 914 M_NOWAIT | M_ZERO); 915 916 if (devid != NULL) { 917 scsi_inquiry(csio, 918 /*retries*/4, 919 probedone, 920 MSG_SIMPLE_Q_TAG, 921 (uint8_t *)devid, 922 SVPD_DEVICE_ID_MAX_SIZE, 923 /*evpd*/TRUE, 924 SVPD_DEVICE_ID, 925 SSD_MIN_SIZE, 926 /*timeout*/60 * 1000); 927 break; 928 } 929 /* 930 * We'll have to do without, let our probedone 931 * routine finish up for us. 932 */ 933 start_ccb->csio.data_ptr = NULL; 934 probedone(periph, start_ccb); 935 return; 936 } 937 case PROBE_SERIAL_NUM: 938 { 939 struct scsi_vpd_unit_serial_number *serial_buf; 940 struct cam_ed* device; 941 942 serial_buf = NULL; 943 device = periph->path->device; 944 if (device->serial_num != NULL) { 945 free(device->serial_num, M_CAMXPT); 946 device->serial_num = NULL; 947 device->serial_num_len = 0; 948 } 949 950 if (device_has_vpd(device, SVPD_UNIT_SERIAL_NUMBER)) 951 serial_buf = (struct scsi_vpd_unit_serial_number *) 952 malloc(sizeof(*serial_buf), M_CAMXPT, 953 M_NOWAIT|M_ZERO); 954 955 if (serial_buf != NULL) { 956 scsi_inquiry(csio, 957 /*retries*/4, 958 probedone, 959 MSG_SIMPLE_Q_TAG, 960 (u_int8_t *)serial_buf, 961 sizeof(*serial_buf), 962 /*evpd*/TRUE, 963 SVPD_UNIT_SERIAL_NUMBER, 964 SSD_MIN_SIZE, 965 /*timeout*/60 * 1000); 966 break; 967 } 968 /* 969 * We'll have to do without, let our probedone 970 * routine finish up for us. 971 */ 972 start_ccb->csio.data_ptr = NULL; 973 probedone(periph, start_ccb); 974 return; 975 } 976 default: 977 panic("probestart: invalid action state 0x%x\n", softc->action); 978 } 979 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE; 980 xpt_action(start_ccb); 981} 982 983static void 984proberequestdefaultnegotiation(struct cam_periph *periph) 985{ 986 struct ccb_trans_settings cts; 987 988 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); 989 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 990 cts.type = CTS_TYPE_USER_SETTINGS; 991 xpt_action((union ccb *)&cts); 992 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 993 return; 994 } 995 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 996 cts.type = CTS_TYPE_CURRENT_SETTINGS; 997 xpt_action((union ccb *)&cts); 998} 999 1000/* 1001 * Backoff Negotiation Code- only pertinent for SPI devices. 1002 */ 1003static int 1004proberequestbackoff(struct cam_periph *periph, struct cam_ed *device) 1005{ 1006 struct ccb_trans_settings cts; 1007 struct ccb_trans_settings_spi *spi; 1008 1009 memset(&cts, 0, sizeof (cts)); 1010 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); 1011 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 1012 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1013 xpt_action((union ccb *)&cts); 1014 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1015 if (bootverbose) { 1016 xpt_print(periph->path, 1017 "failed to get current device settings\n"); 1018 } 1019 return (0); 1020 } 1021 if (cts.transport != XPORT_SPI) { 1022 if (bootverbose) { 1023 xpt_print(periph->path, "not SPI transport\n"); 1024 } 1025 return (0); 1026 } 1027 spi = &cts.xport_specific.spi; 1028 1029 /* 1030 * We cannot renegotiate sync rate if we don't have one. 1031 */ 1032 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) { 1033 if (bootverbose) { 1034 xpt_print(periph->path, "no sync rate known\n"); 1035 } 1036 return (0); 1037 } 1038 1039 /* 1040 * We'll assert that we don't have to touch PPR options- the 1041 * SIM will see what we do with period and offset and adjust 1042 * the PPR options as appropriate. 1043 */ 1044 1045 /* 1046 * A sync rate with unknown or zero offset is nonsensical. 1047 * A sync period of zero means Async. 1048 */ 1049 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0 1050 || spi->sync_offset == 0 || spi->sync_period == 0) { 1051 if (bootverbose) { 1052 xpt_print(periph->path, "no sync rate available\n"); 1053 } 1054 return (0); 1055 } 1056 1057 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) { 1058 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1059 ("hit async: giving up on DV\n")); 1060 return (0); 1061 } 1062 1063 1064 /* 1065 * Jump sync_period up by one, but stop at 5MHz and fall back to Async. 1066 * We don't try to remember 'last' settings to see if the SIM actually 1067 * gets into the speed we want to set. We check on the SIM telling 1068 * us that a requested speed is bad, but otherwise don't try and 1069 * check the speed due to the asynchronous and handshake nature 1070 * of speed setting. 1071 */ 1072 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET; 1073 for (;;) { 1074 spi->sync_period++; 1075 if (spi->sync_period >= 0xf) { 1076 spi->sync_period = 0; 1077 spi->sync_offset = 0; 1078 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1079 ("setting to async for DV\n")); 1080 /* 1081 * Once we hit async, we don't want to try 1082 * any more settings. 1083 */ 1084 device->flags |= CAM_DEV_DV_HIT_BOTTOM; 1085 } else if (bootverbose) { 1086 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1087 ("DV: period 0x%x\n", spi->sync_period)); 1088 printf("setting period to 0x%x\n", spi->sync_period); 1089 } 1090 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; 1091 cts.type = CTS_TYPE_CURRENT_SETTINGS; 1092 xpt_action((union ccb *)&cts); 1093 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1094 break; 1095 } 1096 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1097 ("DV: failed to set period 0x%x\n", spi->sync_period)); 1098 if (spi->sync_period == 0) { 1099 return (0); 1100 } 1101 } 1102 return (1); 1103} 1104 1105#define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP) 1106 1107static void 1108probedone(struct cam_periph *periph, union ccb *done_ccb) 1109{ 1110 probe_softc *softc; 1111 struct cam_path *path; 1112 u_int32_t priority; 1113 1114 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n")); 1115 1116 softc = (probe_softc *)periph->softc; 1117 path = done_ccb->ccb_h.path; 1118 priority = done_ccb->ccb_h.pinfo.priority; 1119 1120 switch (softc->action) { 1121 case PROBE_TUR: 1122 { 1123 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1124 1125 if (cam_periph_error(done_ccb, 0, 1126 SF_NO_PRINT, NULL) == ERESTART) { 1127out: 1128 /* Drop freeze taken due to CAM_DEV_QFREEZE */ 1129 cam_release_devq(path, 0, 0, 0, FALSE); 1130 return; 1131 } 1132 else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 1133 /* Don't wedge the queue */ 1134 xpt_release_devq(done_ccb->ccb_h.path, 1135 /*count*/1, 1136 /*run_queue*/TRUE); 1137 } 1138 PROBE_SET_ACTION(softc, PROBE_INQUIRY); 1139 xpt_release_ccb(done_ccb); 1140 xpt_schedule(periph, priority); 1141 goto out; 1142 } 1143 case PROBE_INQUIRY: 1144 case PROBE_FULL_INQUIRY: 1145 { 1146 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1147 struct scsi_inquiry_data *inq_buf; 1148 u_int8_t periph_qual; 1149 1150 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; 1151 inq_buf = &path->device->inq_data; 1152 1153 periph_qual = SID_QUAL(inq_buf); 1154 1155 if (periph_qual == SID_QUAL_LU_CONNECTED) { 1156 u_int8_t len; 1157 1158 /* 1159 * We conservatively request only 1160 * SHORT_INQUIRY_LEN bytes of inquiry 1161 * information during our first try 1162 * at sending an INQUIRY. If the device 1163 * has more information to give, 1164 * perform a second request specifying 1165 * the amount of information the device 1166 * is willing to give. 1167 */ 1168 len = inq_buf->additional_length 1169 + offsetof(struct scsi_inquiry_data, 1170 additional_length) + 1; 1171 if (softc->action == PROBE_INQUIRY 1172 && len > SHORT_INQUIRY_LENGTH) { 1173 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY); 1174 xpt_release_ccb(done_ccb); 1175 xpt_schedule(periph, priority); 1176 goto out; 1177 } 1178 1179 scsi_find_quirk(path->device); 1180 1181 scsi_devise_transport(path); 1182 1183 if (path->device->lun_id == 0 && 1184 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 && 1185 (SCSI_QUIRK(path->device)->quirks & 1186 CAM_QUIRK_NORPTLUNS) == 0) { 1187 PROBE_SET_ACTION(softc, 1188 PROBE_REPORT_LUNS); 1189 /* 1190 * Start with room for *one* lun. 1191 */ 1192 periph->path->target->rpl_size = 16; 1193 } else if (INQ_DATA_TQ_ENABLED(inq_buf)) 1194 PROBE_SET_ACTION(softc, 1195 PROBE_MODE_SENSE); 1196 else 1197 PROBE_SET_ACTION(softc, 1198 PROBE_SUPPORTED_VPD_LIST); 1199 1200 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1201 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1202 xpt_acquire_device(path->device); 1203 } 1204 xpt_release_ccb(done_ccb); 1205 xpt_schedule(periph, priority); 1206 goto out; 1207 } else if (path->device->lun_id == 0 && 1208 SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 && 1209 (SCSI_QUIRK(path->device)->quirks & 1210 CAM_QUIRK_NORPTLUNS) == 0) { 1211 if (path->device->flags & 1212 CAM_DEV_UNCONFIGURED) { 1213 path->device->flags &= 1214 ~CAM_DEV_UNCONFIGURED; 1215 xpt_acquire_device(path->device); 1216 } 1217 PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS); 1218 periph->path->target->rpl_size = 16; 1219 xpt_release_ccb(done_ccb); 1220 xpt_schedule(periph, priority); 1221 goto out; 1222 } 1223 } else if (cam_periph_error(done_ccb, 0, 1224 done_ccb->ccb_h.target_lun > 0 1225 ? SF_RETRY_UA|SF_QUIET_IR 1226 : SF_RETRY_UA, 1227 &softc->saved_ccb) == ERESTART) { 1228 goto out; 1229 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1230 /* Don't wedge the queue */ 1231 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1232 /*run_queue*/TRUE); 1233 } 1234 /* 1235 * If we get to this point, we got an error status back 1236 * from the inquiry and the error status doesn't require 1237 * automatically retrying the command. Therefore, the 1238 * inquiry failed. If we had inquiry information before 1239 * for this device, but this latest inquiry command failed, 1240 * the device has probably gone away. If this device isn't 1241 * already marked unconfigured, notify the peripheral 1242 * drivers that this device is no more. 1243 */ 1244 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) 1245 /* Send the async notification. */ 1246 xpt_async(AC_LOST_DEVICE, path, NULL); 1247 PROBE_SET_ACTION(softc, PROBE_INVALID); 1248 1249 xpt_release_ccb(done_ccb); 1250 break; 1251 } 1252 case PROBE_REPORT_LUNS: 1253 { 1254 struct ccb_scsiio *csio; 1255 struct scsi_report_luns_data *lp; 1256 u_int nlun, maxlun; 1257 1258 csio = &done_ccb->csio; 1259 1260 lp = (struct scsi_report_luns_data *)csio->data_ptr; 1261 nlun = scsi_4btoul(lp->length) / 8; 1262 maxlun = (csio->dxfer_len / 8) - 1; 1263 1264 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1265 if (cam_periph_error(done_ccb, 0, 1266 done_ccb->ccb_h.target_lun > 0 ? 1267 SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA, 1268 &softc->saved_ccb) == ERESTART) { 1269 goto out; 1270 } 1271 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1272 xpt_release_devq(done_ccb->ccb_h.path, 1, 1273 TRUE); 1274 } 1275 free(lp, M_CAMXPT); 1276 lp = NULL; 1277 } else if (nlun > maxlun) { 1278 /* 1279 * Reallocate and retry to cover all luns 1280 */ 1281 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1282 ("Probe: reallocating REPORT_LUNS for %u luns\n", 1283 nlun)); 1284 free(lp, M_CAMXPT); 1285 path->target->rpl_size = (nlun << 3) + 8; 1286 xpt_release_ccb(done_ccb); 1287 xpt_schedule(periph, priority); 1288 goto out; 1289 } else if (nlun == 0) { 1290 /* 1291 * If there don't appear to be any luns, bail. 1292 */ 1293 free(lp, M_CAMXPT); 1294 lp = NULL; 1295 } else if (probe_strange_rpl_data(lp, maxlun)) { 1296 /* 1297 * If we can't understand the lun format 1298 * of any entry, bail. 1299 */ 1300 free(lp, M_CAMXPT); 1301 lp = NULL; 1302 } else { 1303 lun_id_t lun; 1304 int idx; 1305 1306 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1307 ("Probe: %u lun(s) reported\n", nlun)); 1308 1309 CAM_GET_SIMPLE_LUN(lp, 0, lun); 1310 /* 1311 * If the first lun is not lun 0, then either there 1312 * is no lun 0 in the list, or the list is unsorted. 1313 */ 1314 if (lun != 0) { 1315 for (idx = 0; idx < nlun; idx++) { 1316 CAM_GET_SIMPLE_LUN(lp, idx, lun); 1317 if (lun == 0) { 1318 break; 1319 } 1320 } 1321 if (idx != nlun) { 1322 uint8_t tlun[8]; 1323 memcpy(tlun, 1324 lp->luns[0].lundata, 8); 1325 memcpy(lp->luns[0].lundata, 1326 lp->luns[idx].lundata, 8); 1327 memcpy(lp->luns[idx].lundata, 1328 tlun, 8); 1329 CAM_DEBUG(path, CAM_DEBUG_PROBE, 1330 ("lun 0 in position %u\n", idx)); 1331 } else { 1332 /* 1333 * There is no lun 0 in our list. Destroy 1334 * the validity of the inquiry data so we 1335 * bail here and now. 1336 */ 1337 path->device->flags &= 1338 ~CAM_DEV_INQUIRY_DATA_VALID; 1339 } 1340 } 1341 /* 1342 * If we have an old lun list, We can either 1343 * retest luns that appear to have been dropped, 1344 * or just nuke them. We'll opt for the latter. 1345 * This function will also install the new list 1346 * in the target structure. 1347 */ 1348 probe_purge_old(path, lp); 1349 lp = NULL; 1350 } 1351 if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) { 1352 struct scsi_inquiry_data *inq_buf; 1353 inq_buf = &path->device->inq_data; 1354 if (INQ_DATA_TQ_ENABLED(inq_buf)) 1355 PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); 1356 else 1357 PROBE_SET_ACTION(softc, 1358 PROBE_SUPPORTED_VPD_LIST); 1359 xpt_release_ccb(done_ccb); 1360 xpt_schedule(periph, priority); 1361 goto out; 1362 } 1363 if (lp) { 1364 free(lp, M_CAMXPT); 1365 } 1366 break; 1367 } 1368 case PROBE_MODE_SENSE: 1369 { 1370 struct ccb_scsiio *csio; 1371 struct scsi_mode_header_6 *mode_hdr; 1372 1373 csio = &done_ccb->csio; 1374 mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr; 1375 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 1376 struct scsi_control_page *page; 1377 u_int8_t *offset; 1378 1379 offset = ((u_int8_t *)&mode_hdr[1]) 1380 + mode_hdr->blk_desc_len; 1381 page = (struct scsi_control_page *)offset; 1382 path->device->queue_flags = page->queue_flags; 1383 } else if (cam_periph_error(done_ccb, 0, 1384 SF_RETRY_UA|SF_NO_PRINT, 1385 &softc->saved_ccb) == ERESTART) { 1386 goto out; 1387 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1388 /* Don't wedge the queue */ 1389 xpt_release_devq(done_ccb->ccb_h.path, 1390 /*count*/1, /*run_queue*/TRUE); 1391 } 1392 xpt_release_ccb(done_ccb); 1393 free(mode_hdr, M_CAMXPT); 1394 PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); 1395 xpt_schedule(periph, priority); 1396 goto out; 1397 } 1398 case PROBE_SUPPORTED_VPD_LIST: 1399 { 1400 struct ccb_scsiio *csio; 1401 struct scsi_vpd_supported_page_list *page_list; 1402 1403 csio = &done_ccb->csio; 1404 page_list = 1405 (struct scsi_vpd_supported_page_list *)csio->data_ptr; 1406 1407 if (path->device->supported_vpds != NULL) { 1408 free(path->device->supported_vpds, M_CAMXPT); 1409 path->device->supported_vpds = NULL; 1410 path->device->supported_vpds_len = 0; 1411 } 1412 1413 if (page_list == NULL) { 1414 /* 1415 * Don't process the command as it was never sent 1416 */ 1417 } else if (CCB_COMPLETED_OK(csio->ccb_h)) { 1418 /* Got vpd list */ 1419 path->device->supported_vpds_len = page_list->length + 1420 SVPD_SUPPORTED_PAGES_HDR_LEN; 1421 path->device->supported_vpds = (uint8_t *)page_list; 1422 xpt_release_ccb(done_ccb); 1423 PROBE_SET_ACTION(softc, PROBE_DEVICE_ID); 1424 xpt_schedule(periph, priority); 1425 goto out; 1426 } else if (cam_periph_error(done_ccb, 0, 1427 SF_RETRY_UA|SF_NO_PRINT, 1428 &softc->saved_ccb) == ERESTART) { 1429 goto out; 1430 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1431 /* Don't wedge the queue */ 1432 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1433 /*run_queue*/TRUE); 1434 } 1435 1436 if (page_list) 1437 free(page_list, M_CAMXPT); 1438 /* No VPDs available, skip to device check. */ 1439 csio->data_ptr = NULL; 1440 goto probe_device_check; 1441 } 1442 case PROBE_DEVICE_ID: 1443 { 1444 struct scsi_vpd_device_id *devid; 1445 struct ccb_scsiio *csio; 1446 uint32_t length = 0; 1447 1448 csio = &done_ccb->csio; 1449 devid = (struct scsi_vpd_device_id *)csio->data_ptr; 1450 1451 /* Clean up from previous instance of this device */ 1452 if (path->device->device_id != NULL) { 1453 path->device->device_id_len = 0; 1454 free(path->device->device_id, M_CAMXPT); 1455 path->device->device_id = NULL; 1456 } 1457 1458 if (devid == NULL) { 1459 /* Don't process the command as it was never sent */ 1460 } else if (CCB_COMPLETED_OK(csio->ccb_h)) { 1461 length = scsi_2btoul(devid->length); 1462 if (length != 0) { 1463 /* 1464 * NB: device_id_len is actual response 1465 * size, not buffer size. 1466 */ 1467 path->device->device_id_len = length + 1468 SVPD_DEVICE_ID_HDR_LEN; 1469 path->device->device_id = (uint8_t *)devid; 1470 } 1471 } else if (cam_periph_error(done_ccb, 0, 1472 SF_RETRY_UA, 1473 &softc->saved_ccb) == ERESTART) { 1474 goto out; 1475 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1476 /* Don't wedge the queue */ 1477 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1478 /*run_queue*/TRUE); 1479 } 1480 1481 /* Free the device id space if we don't use it */ 1482 if (devid && length == 0) 1483 free(devid, M_CAMXPT); 1484 xpt_release_ccb(done_ccb); 1485 PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM); 1486 xpt_schedule(periph, priority); 1487 goto out; 1488 } 1489 1490probe_device_check: 1491 case PROBE_SERIAL_NUM: 1492 { 1493 struct ccb_scsiio *csio; 1494 struct scsi_vpd_unit_serial_number *serial_buf; 1495 u_int32_t priority; 1496 int changed; 1497 int have_serialnum; 1498 1499 changed = 1; 1500 have_serialnum = 0; 1501 csio = &done_ccb->csio; 1502 priority = done_ccb->ccb_h.pinfo.priority; 1503 serial_buf = 1504 (struct scsi_vpd_unit_serial_number *)csio->data_ptr; 1505 1506 if (serial_buf == NULL) { 1507 /* 1508 * Don't process the command as it was never sent 1509 */ 1510 } else if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP 1511 && (serial_buf->length > 0)) { 1512 1513 have_serialnum = 1; 1514 path->device->serial_num = 1515 (u_int8_t *)malloc((serial_buf->length + 1), 1516 M_CAMXPT, M_NOWAIT); 1517 if (path->device->serial_num != NULL) { 1518 memcpy(path->device->serial_num, 1519 serial_buf->serial_num, 1520 serial_buf->length); 1521 path->device->serial_num_len = 1522 serial_buf->length; 1523 path->device->serial_num[serial_buf->length] 1524 = '\0'; 1525 } 1526 } else if (cam_periph_error(done_ccb, 0, 1527 SF_RETRY_UA|SF_NO_PRINT, 1528 &softc->saved_ccb) == ERESTART) { 1529 goto out; 1530 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1531 /* Don't wedge the queue */ 1532 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1533 /*run_queue*/TRUE); 1534 } 1535 1536 /* 1537 * Let's see if we have seen this device before. 1538 */ 1539 if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) { 1540 MD5_CTX context; 1541 u_int8_t digest[16]; 1542 1543 MD5Init(&context); 1544 1545 MD5Update(&context, 1546 (unsigned char *)&path->device->inq_data, 1547 sizeof(struct scsi_inquiry_data)); 1548 1549 if (have_serialnum) 1550 MD5Update(&context, serial_buf->serial_num, 1551 serial_buf->length); 1552 1553 MD5Final(digest, &context); 1554 if (bcmp(softc->digest, digest, 16) == 0) 1555 changed = 0; 1556 1557 /* 1558 * XXX Do we need to do a TUR in order to ensure 1559 * that the device really hasn't changed??? 1560 */ 1561 if ((changed != 0) 1562 && ((softc->flags & PROBE_NO_ANNOUNCE) == 0)) 1563 xpt_async(AC_LOST_DEVICE, path, NULL); 1564 } 1565 if (serial_buf != NULL) 1566 free(serial_buf, M_CAMXPT); 1567 1568 if (changed != 0) { 1569 /* 1570 * Now that we have all the necessary 1571 * information to safely perform transfer 1572 * negotiations... Controllers don't perform 1573 * any negotiation or tagged queuing until 1574 * after the first XPT_SET_TRAN_SETTINGS ccb is 1575 * received. So, on a new device, just retrieve 1576 * the user settings, and set them as the current 1577 * settings to set the device up. 1578 */ 1579 proberequestdefaultnegotiation(periph); 1580 xpt_release_ccb(done_ccb); 1581 1582 /* 1583 * Perform a TUR to allow the controller to 1584 * perform any necessary transfer negotiation. 1585 */ 1586 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); 1587 xpt_schedule(periph, priority); 1588 goto out; 1589 } 1590 xpt_release_ccb(done_ccb); 1591 break; 1592 } 1593 case PROBE_TUR_FOR_NEGOTIATION: 1594 case PROBE_DV_EXIT: 1595 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1596 cam_periph_error(done_ccb, 0, 1597 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); 1598 } 1599 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1600 /* Don't wedge the queue */ 1601 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1602 /*run_queue*/TRUE); 1603 } 1604 /* 1605 * Do Domain Validation for lun 0 on devices that claim 1606 * to support Synchronous Transfer modes. 1607 */ 1608 if (softc->action == PROBE_TUR_FOR_NEGOTIATION 1609 && done_ccb->ccb_h.target_lun == 0 1610 && (path->device->inq_data.flags & SID_Sync) != 0 1611 && (path->device->flags & CAM_DEV_IN_DV) == 0) { 1612 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1613 ("Begin Domain Validation\n")); 1614 path->device->flags |= CAM_DEV_IN_DV; 1615 xpt_release_ccb(done_ccb); 1616 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1); 1617 xpt_schedule(periph, priority); 1618 goto out; 1619 } 1620 if (softc->action == PROBE_DV_EXIT) { 1621 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1622 ("Leave Domain Validation\n")); 1623 } 1624 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1625 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1626 xpt_acquire_device(path->device); 1627 } 1628 path->device->flags &= 1629 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); 1630 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { 1631 /* Inform the XPT that a new device has been found */ 1632 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 1633 xpt_action(done_ccb); 1634 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 1635 done_ccb); 1636 } 1637 PROBE_SET_ACTION(softc, PROBE_DONE); 1638 xpt_release_ccb(done_ccb); 1639 break; 1640 case PROBE_INQUIRY_BASIC_DV1: 1641 case PROBE_INQUIRY_BASIC_DV2: 1642 { 1643 struct scsi_inquiry_data *nbuf; 1644 struct ccb_scsiio *csio; 1645 1646 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 1647 cam_periph_error(done_ccb, 0, 1648 SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); 1649 } 1650 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 1651 /* Don't wedge the queue */ 1652 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, 1653 /*run_queue*/TRUE); 1654 } 1655 csio = &done_ccb->csio; 1656 nbuf = (struct scsi_inquiry_data *)csio->data_ptr; 1657 if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) { 1658 xpt_print(path, 1659 "inquiry data fails comparison at DV%d step\n", 1660 softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2); 1661 if (proberequestbackoff(periph, path->device)) { 1662 path->device->flags &= ~CAM_DEV_IN_DV; 1663 PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); 1664 } else { 1665 /* give up */ 1666 PROBE_SET_ACTION(softc, PROBE_DV_EXIT); 1667 } 1668 free(nbuf, M_CAMXPT); 1669 xpt_release_ccb(done_ccb); 1670 xpt_schedule(periph, priority); 1671 goto out; 1672 } 1673 free(nbuf, M_CAMXPT); 1674 if (softc->action == PROBE_INQUIRY_BASIC_DV1) { 1675 PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2); 1676 xpt_release_ccb(done_ccb); 1677 xpt_schedule(periph, priority); 1678 goto out; 1679 } 1680 if (softc->action == PROBE_INQUIRY_BASIC_DV2) { 1681 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, 1682 ("Leave Domain Validation Successfully\n")); 1683 } 1684 if (path->device->flags & CAM_DEV_UNCONFIGURED) { 1685 path->device->flags &= ~CAM_DEV_UNCONFIGURED; 1686 xpt_acquire_device(path->device); 1687 } 1688 path->device->flags &= 1689 ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); 1690 if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { 1691 /* Inform the XPT that a new device has been found */ 1692 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; 1693 xpt_action(done_ccb); 1694 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, 1695 done_ccb); 1696 } 1697 PROBE_SET_ACTION(softc, PROBE_DONE); 1698 xpt_release_ccb(done_ccb); 1699 break; 1700 } 1701 default: 1702 panic("probedone: invalid action state 0x%x\n", softc->action); 1703 } 1704 done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); 1705 TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); 1706 done_ccb->ccb_h.status = CAM_REQ_CMP; 1707 xpt_done(done_ccb); 1708 if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { 1709 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n")); 1710 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */ 1711 cam_release_devq(path, 0, 0, 0, FALSE); 1712 cam_periph_invalidate(periph); 1713 cam_periph_release_locked(periph); 1714 } else { 1715 probeschedule(periph); 1716 goto out; 1717 } 1718} 1719 1720static int 1721probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun) 1722{ 1723 uint32_t idx; 1724 uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8)); 1725 1726 for (idx = 0; idx < nlun; idx++) { 1727 if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) { 1728 return (-1); 1729 } 1730 } 1731 return (0); 1732} 1733 1734static void 1735probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new) 1736{ 1737 struct cam_path *tp; 1738 struct scsi_report_luns_data *old; 1739 u_int idx1, idx2, nlun_old, nlun_new, this_lun; 1740 u_int8_t *ol, *nl; 1741 1742 if (path->target == NULL) { 1743 return; 1744 } 1745 if (path->target->luns == NULL) { 1746 path->target->luns = new; 1747 return; 1748 } 1749 old = path->target->luns; 1750 nlun_old = scsi_4btoul(old->length) / 8; 1751 nlun_new = scsi_4btoul(new->length) / 8; 1752 1753 /* 1754 * We are not going to assume sorted lists. Deal. 1755 */ 1756 for (idx1 = 0; idx1 < nlun_old; idx1++) { 1757 ol = old->luns[idx1].lundata; 1758 for (idx2 = 0; idx2 < nlun_new; idx2++) { 1759 nl = new->luns[idx2].lundata; 1760 if (memcmp(nl, ol, 8) == 0) { 1761 break; 1762 } 1763 } 1764 if (idx2 < nlun_new) { 1765 continue; 1766 } 1767 /* 1768 * An 'old' item not in the 'new' list. 1769 * Nuke it. Except that if it is lun 0, 1770 * that would be what the probe state 1771 * machine is currently working on, 1772 * so we won't do that. 1773 * 1774 * We also cannot nuke it if it is 1775 * not in a lun format we understand. 1776 */ 1777 if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) { 1778 continue; 1779 } 1780 CAM_GET_SIMPLE_LUN(old, idx1, this_lun); 1781 if (this_lun == 0) { 1782 continue; 1783 } 1784 if (xpt_create_path(&tp, NULL, xpt_path_path_id(path), 1785 xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) { 1786 xpt_async(AC_LOST_DEVICE, tp, NULL); 1787 xpt_free_path(tp); 1788 } 1789 } 1790 free(old, M_CAMXPT); 1791 path->target->luns = new; 1792} 1793 1794static void 1795probecleanup(struct cam_periph *periph) 1796{ 1797 free(periph->softc, M_CAMXPT); 1798} 1799 1800static void 1801scsi_find_quirk(struct cam_ed *device) 1802{ 1803 struct scsi_quirk_entry *quirk; 1804 caddr_t match; 1805 1806 match = cam_quirkmatch((caddr_t)&device->inq_data, 1807 (caddr_t)scsi_quirk_table, 1808 sizeof(scsi_quirk_table) / 1809 sizeof(*scsi_quirk_table), 1810 sizeof(*scsi_quirk_table), scsi_inquiry_match); 1811 1812 if (match == NULL) 1813 panic("xpt_find_quirk: device didn't match wildcard entry!!"); 1814 1815 quirk = (struct scsi_quirk_entry *)match; 1816 device->quirk = quirk; 1817 device->mintags = quirk->mintags; 1818 device->maxtags = quirk->maxtags; 1819} 1820 1821static int 1822sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS) 1823{ 1824 int error, val; 1825 1826 val = cam_srch_hi; 1827 error = sysctl_handle_int(oidp, &val, 0, req); 1828 if (error != 0 || req->newptr == NULL) 1829 return (error); 1830 if (val == 0 || val == 1) { 1831 cam_srch_hi = val; 1832 return (0); 1833 } else { 1834 return (EINVAL); 1835 } 1836} 1837 1838typedef struct { 1839 union ccb *request_ccb; 1840 struct ccb_pathinq *cpi; 1841 int counter; 1842 int lunindex[0]; 1843} scsi_scan_bus_info; 1844 1845/* 1846 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. 1847 * As the scan progresses, scsi_scan_bus is used as the 1848 * callback on completion function. 1849 */ 1850static void 1851scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) 1852{ 1853 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1854 ("scsi_scan_bus\n")); 1855 switch (request_ccb->ccb_h.func_code) { 1856 case XPT_SCAN_BUS: 1857 case XPT_SCAN_TGT: 1858 { 1859 scsi_scan_bus_info *scan_info; 1860 union ccb *work_ccb, *reset_ccb; 1861 struct cam_path *path; 1862 u_int i; 1863 u_int low_target, max_target; 1864 u_int initiator_id; 1865 1866 /* Find out the characteristics of the bus */ 1867 work_ccb = xpt_alloc_ccb_nowait(); 1868 if (work_ccb == NULL) { 1869 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 1870 xpt_done(request_ccb); 1871 return; 1872 } 1873 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path, 1874 request_ccb->ccb_h.pinfo.priority); 1875 work_ccb->ccb_h.func_code = XPT_PATH_INQ; 1876 xpt_action(work_ccb); 1877 if (work_ccb->ccb_h.status != CAM_REQ_CMP) { 1878 request_ccb->ccb_h.status = work_ccb->ccb_h.status; 1879 xpt_free_ccb(work_ccb); 1880 xpt_done(request_ccb); 1881 return; 1882 } 1883 1884 if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) { 1885 /* 1886 * Can't scan the bus on an adapter that 1887 * cannot perform the initiator role. 1888 */ 1889 request_ccb->ccb_h.status = CAM_REQ_CMP; 1890 xpt_free_ccb(work_ccb); 1891 xpt_done(request_ccb); 1892 return; 1893 } 1894 1895 /* We may need to reset bus first, if we haven't done it yet. */ 1896 if ((work_ccb->cpi.hba_inquiry & 1897 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) && 1898 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) && 1899 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) { 1900 reset_ccb = xpt_alloc_ccb_nowait(); 1901 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path, 1902 CAM_PRIORITY_NONE); 1903 reset_ccb->ccb_h.func_code = XPT_RESET_BUS; 1904 xpt_action(reset_ccb); 1905 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) { 1906 request_ccb->ccb_h.status = reset_ccb->ccb_h.status; 1907 xpt_free_ccb(reset_ccb); 1908 xpt_free_ccb(work_ccb); 1909 xpt_done(request_ccb); 1910 return; 1911 } 1912 xpt_free_ccb(reset_ccb); 1913 } 1914 1915 /* Save some state for use while we probe for devices */ 1916 scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) + 1917 (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT); 1918 if (scan_info == NULL) { 1919 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; 1920 xpt_done(request_ccb); 1921 return; 1922 } 1923 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, 1924 ("SCAN start for %p\n", scan_info)); 1925 scan_info->request_ccb = request_ccb; 1926 scan_info->cpi = &work_ccb->cpi; 1927 1928 /* Cache on our stack so we can work asynchronously */ 1929 max_target = scan_info->cpi->max_target; 1930 low_target = 0; 1931 initiator_id = scan_info->cpi->initiator_id; 1932 1933 1934 /* 1935 * We can scan all targets in parallel, or do it sequentially. 1936 */ 1937 1938 if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) { 1939 max_target = low_target = request_ccb->ccb_h.target_id; 1940 scan_info->counter = 0; 1941 } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) { 1942 max_target = 0; 1943 scan_info->counter = 0; 1944 } else { 1945 scan_info->counter = scan_info->cpi->max_target + 1; 1946 if (scan_info->cpi->initiator_id < scan_info->counter) { 1947 scan_info->counter--; 1948 } 1949 } 1950 1951 for (i = low_target; i <= max_target; i++) { 1952 cam_status status; 1953 if (i == initiator_id) 1954 continue; 1955
|