1 /* $OpenBSD: scsi_base.c,v 1.214 2014/07/01 02:31:16 dlg Exp $ */ 2 /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ 3 4 /* 5 * Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Charles M. Hannum. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Originally written by Julian Elischer (julian@dialix.oz.au) 35 * Detailed SCSI error printing Copyright 1997 by Matthew Jacob. 36 */ 37 38 #include <sys/types.h> 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/buf.h> 43 #include <sys/uio.h> 44 #include <sys/errno.h> 45 #include <sys/device.h> 46 #include <sys/proc.h> 47 #include <sys/pool.h> 48 49 #include <scsi/scsi_all.h> 50 #include <scsi/scsi_disk.h> 51 #include <scsi/scsiconf.h> 52 53 static __inline void asc2ascii(u_int8_t, u_int8_t ascq, char *result, 54 size_t len); 55 int scsi_xs_error(struct scsi_xfer *); 56 char *scsi_decode_sense(struct scsi_sense_data *, int); 57 58 void scsi_xs_sync_done(struct scsi_xfer *); 59 60 /* Values for flag parameter to scsi_decode_sense. */ 61 #define DECODE_SENSE_KEY 1 62 #define DECODE_ASC_ASCQ 2 63 #define DECODE_SKSV 3 64 65 struct pool scsi_xfer_pool; 66 struct pool scsi_plug_pool; 67 68 struct scsi_plug { 69 struct workq_task wqt; 70 int target; 71 int lun; 72 int how; 73 }; 74 75 void scsi_plug_probe(void *, void *); 76 void scsi_plug_detach(void *, void *); 77 78 struct scsi_xfer * scsi_xs_io(struct scsi_link *, void *, int); 79 80 int scsi_ioh_pending(struct scsi_iopool *); 81 struct scsi_iohandler * scsi_ioh_deq(struct scsi_iopool *); 82 83 void scsi_xsh_runqueue(struct scsi_link *); 84 void scsi_xsh_ioh(void *, void *); 85 86 int scsi_link_open(struct scsi_link *); 87 void scsi_link_close(struct scsi_link *); 88 89 void * scsi_iopool_get(struct scsi_iopool *); 90 void scsi_iopool_put(struct scsi_iopool *, void *); 91 92 /* ioh/xsh queue state */ 93 #define RUNQ_IDLE 0 94 #define RUNQ_LINKQ 1 95 #define RUNQ_POOLQ 2 96 97 /* synchronous api for allocating an io. */ 98 struct scsi_io_mover { 99 struct mutex mtx; 100 void *io; 101 u_int done; 102 }; 103 #define SCSI_IO_MOVER_INITIALIZER { MUTEX_INITIALIZER(IPL_BIO), NULL, 0 } 104 105 void scsi_move(struct scsi_io_mover *); 106 void scsi_move_done(void *, void *); 107 108 void scsi_io_get_done(void *, void *); 109 void scsi_xs_get_done(void *, void *); 110 111 /* 112 * Called when a scsibus is attached to initialize global data. 113 */ 114 void 115 scsi_init() 116 { 117 static int scsi_init_done; 118 119 if (scsi_init_done) 120 return; 121 scsi_init_done = 1; 122 123 #if defined(SCSI_DELAY) && SCSI_DELAY > 0 124 /* Historical. Older buses may need a moment to stabilize. */ 125 delay(1000000 * SCSI_DELAY); 126 #endif 127 128 /* Initialize the scsi_xfer pool. */ 129 pool_init(&scsi_xfer_pool, sizeof(struct scsi_xfer), 0, 130 0, 0, "scxspl", NULL); 131 pool_setipl(&scsi_xfer_pool, IPL_BIO); 132 /* Initialize the scsi_plug pool */ 133 pool_init(&scsi_plug_pool, sizeof(struct scsi_plug), 0, 134 0, 0, "scsiplug", NULL); 135 pool_setipl(&scsi_plug_pool, IPL_BIO); 136 } 137 138 int 139 scsi_req_probe(struct scsibus_softc *sc, int target, int lun) 140 { 141 struct scsi_plug *p; 142 143 p = pool_get(&scsi_plug_pool, PR_NOWAIT); 144 if (p == NULL) 145 return (ENOMEM); 146 147 p->target = target; 148 p->lun = lun; 149 150 workq_queue_task(NULL, &p->wqt, 0, scsi_plug_probe, sc, p); 151 152 return (0); 153 } 154 155 int 156 scsi_req_detach(struct scsibus_softc *sc, int target, int lun, int how) 157 { 158 struct scsi_plug *p; 159 160 p = pool_get(&scsi_plug_pool, PR_NOWAIT); 161 if (p == NULL) 162 return (ENOMEM); 163 164 p->target = target; 165 p->lun = lun; 166 p->how = how; 167 168 workq_queue_task(NULL, &p->wqt, 0, scsi_plug_detach, sc, p); 169 170 return (0); 171 } 172 173 void 174 scsi_plug_probe(void *xsc, void *xp) 175 { 176 struct scsibus_softc *sc = xsc; 177 struct scsi_plug *p = xp; 178 int target = p->target, lun = p->lun; 179 180 pool_put(&scsi_plug_pool, p); 181 182 scsi_probe(sc, target, lun); 183 } 184 185 void 186 scsi_plug_detach(void *xsc, void *xp) 187 { 188 struct scsibus_softc *sc = xsc; 189 struct scsi_plug *p = xp; 190 int target = p->target, lun = p->lun; 191 int how = p->how; 192 193 pool_put(&scsi_plug_pool, p); 194 195 scsi_detach(sc, target, lun, how); 196 } 197 198 int 199 scsi_pending_start(struct mutex *mtx, u_int *running) 200 { 201 int rv = 1; 202 203 mtx_enter(mtx); 204 (*running)++; 205 if ((*running) > 1) 206 rv = 0; 207 mtx_leave(mtx); 208 209 return (rv); 210 } 211 212 int 213 scsi_pending_finish(struct mutex *mtx, u_int *running) 214 { 215 int rv = 1; 216 217 mtx_enter(mtx); 218 (*running)--; 219 if ((*running) > 0) { 220 (*running) = 1; 221 rv = 0; 222 } 223 mtx_leave(mtx); 224 225 return (rv); 226 } 227 228 void 229 scsi_iopool_init(struct scsi_iopool *iopl, void *iocookie, 230 void *(*io_get)(void *), void (*io_put)(void *, void *)) 231 { 232 iopl->iocookie = iocookie; 233 iopl->io_get = io_get; 234 iopl->io_put = io_put; 235 236 TAILQ_INIT(&iopl->queue); 237 iopl->running = 0; 238 mtx_init(&iopl->mtx, IPL_BIO); 239 } 240 241 void * 242 scsi_iopool_get(struct scsi_iopool *iopl) 243 { 244 void *io; 245 246 KERNEL_LOCK(); 247 io = iopl->io_get(iopl->iocookie); 248 KERNEL_UNLOCK(); 249 250 return (io); 251 } 252 253 void 254 scsi_iopool_put(struct scsi_iopool *iopl, void *io) 255 { 256 KERNEL_LOCK(); 257 iopl->io_put(iopl->iocookie, io); 258 KERNEL_UNLOCK(); 259 } 260 261 void 262 scsi_iopool_destroy(struct scsi_iopool *iopl) 263 { 264 struct scsi_runq sleepers = TAILQ_HEAD_INITIALIZER(sleepers); 265 struct scsi_iohandler *ioh = NULL; 266 267 mtx_enter(&iopl->mtx); 268 while ((ioh = TAILQ_FIRST(&iopl->queue)) != NULL) { 269 TAILQ_REMOVE(&iopl->queue, ioh, q_entry); 270 ioh->q_state = RUNQ_IDLE; 271 272 if (ioh->handler == scsi_io_get_done) 273 TAILQ_INSERT_TAIL(&sleepers, ioh, q_entry); 274 #ifdef DIAGNOSTIC 275 else 276 panic("scsi_iopool_destroy: scsi_iohandler on pool"); 277 #endif 278 } 279 mtx_leave(&iopl->mtx); 280 281 while ((ioh = TAILQ_FIRST(&sleepers)) != NULL) { 282 TAILQ_REMOVE(&sleepers, ioh, q_entry); 283 ioh->handler(ioh->cookie, NULL); 284 } 285 } 286 287 void * 288 scsi_default_get(void *iocookie) 289 { 290 return (SCSI_IOPOOL_POISON); 291 } 292 293 void 294 scsi_default_put(void *iocookie, void *io) 295 { 296 #ifdef DIAGNOSTIC 297 if (io != SCSI_IOPOOL_POISON) 298 panic("unexpected opening returned"); 299 #endif 300 } 301 302 /* 303 * public interface to the ioh api. 304 */ 305 306 void 307 scsi_ioh_set(struct scsi_iohandler *ioh, struct scsi_iopool *iopl, 308 void (*handler)(void *, void *), void *cookie) 309 { 310 ioh->q_state = RUNQ_IDLE; 311 ioh->pool = iopl; 312 ioh->handler = handler; 313 ioh->cookie = cookie; 314 } 315 316 int 317 scsi_ioh_add(struct scsi_iohandler *ioh) 318 { 319 struct scsi_iopool *iopl = ioh->pool; 320 int rv = 0; 321 322 mtx_enter(&iopl->mtx); 323 switch (ioh->q_state) { 324 case RUNQ_IDLE: 325 TAILQ_INSERT_TAIL(&iopl->queue, ioh, q_entry); 326 ioh->q_state = RUNQ_POOLQ; 327 rv = 1; 328 break; 329 #ifdef DIAGNOSTIC 330 case RUNQ_POOLQ: 331 break; 332 default: 333 panic("scsi_ioh_add: unexpected state %u", ioh->q_state); 334 #endif 335 } 336 mtx_leave(&iopl->mtx); 337 338 /* lets get some io up in the air */ 339 scsi_iopool_run(iopl); 340 341 return (rv); 342 } 343 344 int 345 scsi_ioh_del(struct scsi_iohandler *ioh) 346 { 347 struct scsi_iopool *iopl = ioh->pool; 348 int rv = 0; 349 350 mtx_enter(&iopl->mtx); 351 switch (ioh->q_state) { 352 case RUNQ_POOLQ: 353 TAILQ_REMOVE(&iopl->queue, ioh, q_entry); 354 ioh->q_state = RUNQ_IDLE; 355 rv = 1; 356 break; 357 #ifdef DIAGNOSTIC 358 case RUNQ_IDLE: 359 break; 360 default: 361 panic("scsi_ioh_del: unexpected state %u", ioh->q_state); 362 #endif 363 } 364 mtx_leave(&iopl->mtx); 365 366 return (rv); 367 } 368 369 /* 370 * internal iopool runqueue handling. 371 */ 372 373 struct scsi_iohandler * 374 scsi_ioh_deq(struct scsi_iopool *iopl) 375 { 376 struct scsi_iohandler *ioh = NULL; 377 378 mtx_enter(&iopl->mtx); 379 ioh = TAILQ_FIRST(&iopl->queue); 380 if (ioh != NULL) { 381 TAILQ_REMOVE(&iopl->queue, ioh, q_entry); 382 ioh->q_state = RUNQ_IDLE; 383 } 384 mtx_leave(&iopl->mtx); 385 386 return (ioh); 387 } 388 389 int 390 scsi_ioh_pending(struct scsi_iopool *iopl) 391 { 392 int rv; 393 394 mtx_enter(&iopl->mtx); 395 rv = !TAILQ_EMPTY(&iopl->queue); 396 mtx_leave(&iopl->mtx); 397 398 return (rv); 399 } 400 401 void 402 scsi_iopool_run(struct scsi_iopool *iopl) 403 { 404 struct scsi_iohandler *ioh; 405 void *io; 406 407 if (!scsi_pending_start(&iopl->mtx, &iopl->running)) 408 return; 409 do { 410 while (scsi_ioh_pending(iopl)) { 411 io = scsi_iopool_get(iopl); 412 if (io == NULL) 413 break; 414 415 ioh = scsi_ioh_deq(iopl); 416 if (ioh == NULL) { 417 scsi_iopool_put(iopl, io); 418 break; 419 } 420 421 ioh->handler(ioh->cookie, io); 422 } 423 } while (!scsi_pending_finish(&iopl->mtx, &iopl->running)); 424 } 425 426 /* 427 * move an io from a runq to a proc thats waiting for an io. 428 */ 429 430 void 431 scsi_move(struct scsi_io_mover *m) 432 { 433 mtx_enter(&m->mtx); 434 while (!m->done) 435 msleep(m, &m->mtx, PRIBIO, "scsiiomv", 0); 436 mtx_leave(&m->mtx); 437 } 438 439 void 440 scsi_move_done(void *cookie, void *io) 441 { 442 struct scsi_io_mover *m = cookie; 443 444 mtx_enter(&m->mtx); 445 m->io = io; 446 m->done = 1; 447 wakeup_one(m); 448 mtx_leave(&m->mtx); 449 } 450 451 /* 452 * synchronous api for allocating an io. 453 */ 454 455 void * 456 scsi_io_get(struct scsi_iopool *iopl, int flags) 457 { 458 struct scsi_io_mover m = SCSI_IO_MOVER_INITIALIZER; 459 struct scsi_iohandler ioh; 460 void *io; 461 462 /* try and sneak an io off the backend immediately */ 463 io = scsi_iopool_get(iopl); 464 if (io != NULL) 465 return (io); 466 else if (ISSET(flags, SCSI_NOSLEEP)) 467 return (NULL); 468 469 /* otherwise sleep until we get one */ 470 scsi_ioh_set(&ioh, iopl, scsi_io_get_done, &m); 471 scsi_ioh_add(&ioh); 472 scsi_move(&m); 473 474 return (m.io); 475 } 476 477 void 478 scsi_io_get_done(void *cookie, void *io) 479 { 480 scsi_move_done(cookie, io); 481 } 482 483 void 484 scsi_io_put(struct scsi_iopool *iopl, void *io) 485 { 486 scsi_iopool_put(iopl, io); 487 scsi_iopool_run(iopl); 488 } 489 490 /* 491 * public interface to the xsh api. 492 */ 493 494 void 495 scsi_xsh_set(struct scsi_xshandler *xsh, struct scsi_link *link, 496 void (*handler)(struct scsi_xfer *)) 497 { 498 scsi_ioh_set(&xsh->ioh, link->pool, scsi_xsh_ioh, xsh); 499 500 xsh->link = link; 501 xsh->handler = handler; 502 } 503 504 int 505 scsi_xsh_add(struct scsi_xshandler *xsh) 506 { 507 struct scsi_link *link = xsh->link; 508 int rv = 0; 509 510 if (ISSET(link->state, SDEV_S_DYING)) 511 return (0); 512 513 mtx_enter(&link->pool->mtx); 514 if (xsh->ioh.q_state == RUNQ_IDLE) { 515 TAILQ_INSERT_TAIL(&link->queue, &xsh->ioh, q_entry); 516 xsh->ioh.q_state = RUNQ_LINKQ; 517 rv = 1; 518 } 519 mtx_leave(&link->pool->mtx); 520 521 /* lets get some io up in the air */ 522 scsi_xsh_runqueue(link); 523 524 return (rv); 525 } 526 527 int 528 scsi_xsh_del(struct scsi_xshandler *xsh) 529 { 530 struct scsi_link *link = xsh->link; 531 int rv = 1; 532 533 mtx_enter(&link->pool->mtx); 534 switch (xsh->ioh.q_state) { 535 case RUNQ_IDLE: 536 rv = 0; 537 break; 538 case RUNQ_LINKQ: 539 TAILQ_REMOVE(&link->queue, &xsh->ioh, q_entry); 540 break; 541 case RUNQ_POOLQ: 542 TAILQ_REMOVE(&link->pool->queue, &xsh->ioh, q_entry); 543 link->pending--; 544 if (ISSET(link->state, SDEV_S_DYING) && link->pending == 0) 545 wakeup_one(&link->pending); 546 break; 547 default: 548 panic("unexpected xsh state %u", xsh->ioh.q_state); 549 } 550 xsh->ioh.q_state = RUNQ_IDLE; 551 mtx_leave(&link->pool->mtx); 552 553 return (rv); 554 } 555 556 /* 557 * internal xs runqueue handling. 558 */ 559 560 void 561 scsi_xsh_runqueue(struct scsi_link *link) 562 { 563 struct scsi_iohandler *ioh; 564 int runq; 565 566 if (!scsi_pending_start(&link->pool->mtx, &link->running)) 567 return; 568 do { 569 runq = 0; 570 571 mtx_enter(&link->pool->mtx); 572 while (!ISSET(link->state, SDEV_S_DYING) && 573 link->pending < link->openings && 574 ((ioh = TAILQ_FIRST(&link->queue)) != NULL)) { 575 link->pending++; 576 577 TAILQ_REMOVE(&link->queue, ioh, q_entry); 578 TAILQ_INSERT_TAIL(&link->pool->queue, ioh, q_entry); 579 ioh->q_state = RUNQ_POOLQ; 580 581 runq = 1; 582 } 583 mtx_leave(&link->pool->mtx); 584 585 if (runq) 586 scsi_iopool_run(link->pool); 587 } while (!scsi_pending_finish(&link->pool->mtx, &link->running)); 588 } 589 590 void 591 scsi_xsh_ioh(void *cookie, void *io) 592 { 593 struct scsi_xshandler *xsh = cookie; 594 struct scsi_xfer *xs; 595 596 xs = scsi_xs_io(xsh->link, io, SCSI_NOSLEEP); 597 if (xs == NULL) { 598 /* 599 * in this situation we should queue things waiting for an 600 * xs and then give them xses when they were supposed be to 601 * returned to the pool. 602 */ 603 604 printf("scsi_xfer pool exhausted!\n"); 605 scsi_xsh_add(xsh); 606 return; 607 } 608 609 xsh->handler(xs); 610 } 611 612 /* 613 * Get a scsi transfer structure for the caller. 614 * Go to the iopool backend for an "opening" and then attach an xs to it. 615 */ 616 617 struct scsi_xfer * 618 scsi_xs_get(struct scsi_link *link, int flags) 619 { 620 struct scsi_xshandler xsh; 621 struct scsi_io_mover m = SCSI_IO_MOVER_INITIALIZER; 622 623 struct scsi_iopool *iopl = link->pool; 624 void *io; 625 626 if (ISSET(link->state, SDEV_S_DYING)) 627 return (NULL); 628 629 /* really custom xs handler to avoid scsi_xsh_ioh */ 630 scsi_ioh_set(&xsh.ioh, iopl, scsi_xs_get_done, &m); 631 xsh.link = link; 632 633 if (!scsi_link_open(link)) { 634 if (ISSET(flags, SCSI_NOSLEEP)) 635 return (NULL); 636 637 scsi_xsh_add(&xsh); 638 scsi_move(&m); 639 if (m.io == NULL) 640 return (NULL); 641 642 io = m.io; 643 } else if ((io = scsi_iopool_get(iopl)) == NULL) { 644 if (ISSET(flags, SCSI_NOSLEEP)) { 645 scsi_link_close(link); 646 return (NULL); 647 } 648 649 scsi_ioh_add(&xsh.ioh); 650 scsi_move(&m); 651 if (m.io == NULL) 652 return (NULL); 653 654 io = m.io; 655 } 656 657 return (scsi_xs_io(link, io, flags)); 658 } 659 660 void 661 scsi_xs_get_done(void *cookie, void *io) 662 { 663 scsi_move_done(cookie, io); 664 } 665 666 void 667 scsi_link_shutdown(struct scsi_link *link) 668 { 669 struct scsi_runq sleepers = TAILQ_HEAD_INITIALIZER(sleepers); 670 struct scsi_iopool *iopl = link->pool; 671 struct scsi_iohandler *ioh; 672 struct scsi_xshandler *xsh; 673 674 mtx_enter(&iopl->mtx); 675 while ((ioh = TAILQ_FIRST(&link->queue)) != NULL) { 676 TAILQ_REMOVE(&link->queue, ioh, q_entry); 677 ioh->q_state = RUNQ_IDLE; 678 679 if (ioh->handler == scsi_xs_get_done) 680 TAILQ_INSERT_TAIL(&sleepers, ioh, q_entry); 681 #ifdef DIAGNOSTIC 682 else 683 panic("scsi_link_shutdown: scsi_xshandler on link"); 684 #endif 685 } 686 687 ioh = TAILQ_FIRST(&iopl->queue); 688 while (ioh != NULL) { 689 xsh = (struct scsi_xshandler *)ioh; 690 ioh = TAILQ_NEXT(ioh, q_entry); 691 692 #ifdef DIAGNOSTIC 693 if (xsh->ioh.handler == scsi_xsh_ioh && 694 xsh->link == link) 695 panic("scsi_link_shutdown: scsi_xshandler on pool"); 696 #endif 697 698 if (xsh->ioh.handler == scsi_xs_get_done && 699 xsh->link == link) { 700 TAILQ_REMOVE(&iopl->queue, &xsh->ioh, q_entry); 701 xsh->ioh.q_state = RUNQ_IDLE; 702 link->pending--; 703 704 TAILQ_INSERT_TAIL(&sleepers, &xsh->ioh, q_entry); 705 } 706 } 707 708 while (link->pending > 0) 709 msleep(&link->pending, &iopl->mtx, PRIBIO, "pendxs", 0); 710 mtx_leave(&iopl->mtx); 711 712 while ((ioh = TAILQ_FIRST(&sleepers)) != NULL) { 713 TAILQ_REMOVE(&sleepers, ioh, q_entry); 714 ioh->handler(ioh->cookie, NULL); 715 } 716 } 717 718 int 719 scsi_link_open(struct scsi_link *link) 720 { 721 int open = 0; 722 723 mtx_enter(&link->pool->mtx); 724 if (link->pending < link->openings) { 725 link->pending++; 726 open = 1; 727 } 728 mtx_leave(&link->pool->mtx); 729 730 return (open); 731 } 732 733 void 734 scsi_link_close(struct scsi_link *link) 735 { 736 mtx_enter(&link->pool->mtx); 737 link->pending--; 738 if (ISSET(link->state, SDEV_S_DYING) && link->pending == 0) 739 wakeup_one(&link->pending); 740 mtx_leave(&link->pool->mtx); 741 742 scsi_xsh_runqueue(link); 743 } 744 745 struct scsi_xfer * 746 scsi_xs_io(struct scsi_link *link, void *io, int flags) 747 { 748 struct scsi_xfer *xs; 749 750 xs = pool_get(&scsi_xfer_pool, PR_ZERO | 751 (ISSET(flags, SCSI_NOSLEEP) ? PR_NOWAIT : PR_WAITOK)); 752 if (xs == NULL) { 753 scsi_io_put(link->pool, io); 754 scsi_link_close(link); 755 } else { 756 xs->flags = flags; 757 xs->sc_link = link; 758 xs->retries = SCSI_RETRIES; 759 xs->timeout = 10000; 760 xs->cmd = &xs->cmdstore; 761 xs->io = io; 762 } 763 764 return (xs); 765 } 766 767 void 768 scsi_xs_put(struct scsi_xfer *xs) 769 { 770 struct scsi_link *link = xs->sc_link; 771 void *io = xs->io; 772 773 pool_put(&scsi_xfer_pool, xs); 774 775 scsi_io_put(link->pool, io); 776 scsi_link_close(link); 777 } 778 779 /* 780 * Get scsi driver to send a "are you ready?" command 781 */ 782 int 783 scsi_test_unit_ready(struct scsi_link *sc_link, int retries, int flags) 784 { 785 struct scsi_test_unit_ready *cmd; 786 struct scsi_xfer *xs; 787 int error; 788 789 xs = scsi_xs_get(sc_link, flags); 790 if (xs == NULL) 791 return (ENOMEM); 792 xs->cmdlen = sizeof(*cmd); 793 xs->retries = retries; 794 xs->timeout = 10000; 795 796 cmd = (struct scsi_test_unit_ready *)xs->cmd; 797 cmd->opcode = TEST_UNIT_READY; 798 799 error = scsi_xs_sync(xs); 800 scsi_xs_put(xs); 801 802 return (error); 803 } 804 805 void 806 scsi_init_inquiry(struct scsi_xfer *xs, u_int8_t flags, u_int8_t pagecode, 807 void *data, size_t len) 808 { 809 struct scsi_inquiry *cmd; 810 811 cmd = (struct scsi_inquiry *)xs->cmd; 812 cmd->opcode = INQUIRY; 813 cmd->flags = flags; 814 cmd->pagecode = pagecode; 815 _lto2b(len, cmd->length); 816 817 xs->cmdlen = sizeof(*cmd); 818 819 xs->flags |= SCSI_DATA_IN; 820 xs->data = data; 821 xs->datalen = len; 822 } 823 824 /* 825 * Do a scsi operation asking a device what it is. 826 * Use the scsi_cmd routine in the switch table. 827 */ 828 int 829 scsi_inquire(struct scsi_link *link, struct scsi_inquiry_data *inqbuf, 830 int flags) 831 { 832 struct scsi_xfer *xs; 833 int error; 834 835 xs = scsi_xs_get(link, flags); 836 if (xs == NULL) 837 return (EBUSY); 838 839 /* 840 * Ask for only the basic 36 bytes of SCSI2 inquiry information. This 841 * avoids problems with devices that choke trying to supply more. 842 */ 843 scsi_init_inquiry(xs, 0, 0, inqbuf, SID_INQUIRY_HDR + SID_SCSI2_ALEN); 844 845 bzero(inqbuf, sizeof(*inqbuf)); 846 memset(&inqbuf->vendor, ' ', sizeof inqbuf->vendor); 847 memset(&inqbuf->product, ' ', sizeof inqbuf->product); 848 memset(&inqbuf->revision, ' ', sizeof inqbuf->revision); 849 memset(&inqbuf->extra, ' ', sizeof inqbuf->extra); 850 851 error = scsi_xs_sync(xs); 852 853 scsi_xs_put(xs); 854 855 return (error); 856 } 857 858 /* 859 * Query a VPD inquiry page 860 */ 861 int 862 scsi_inquire_vpd(struct scsi_link *sc_link, void *buf, u_int buflen, 863 u_int8_t page, int flags) 864 { 865 struct scsi_xfer *xs; 866 int error; 867 868 if (sc_link->flags & SDEV_UMASS) 869 return (EJUSTRETURN); 870 871 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT); 872 if (xs == NULL) 873 return (ENOMEM); 874 875 xs->retries = 2; 876 xs->timeout = 10000; 877 878 scsi_init_inquiry(xs, SI_EVPD, page, buf, buflen); 879 880 error = scsi_xs_sync(xs); 881 882 scsi_xs_put(xs); 883 884 return (error); 885 } 886 887 /* 888 * Prevent or allow the user to remove the media 889 */ 890 int 891 scsi_prevent(struct scsi_link *sc_link, int type, int flags) 892 { 893 struct scsi_prevent *cmd; 894 struct scsi_xfer *xs; 895 int error; 896 897 if (sc_link->quirks & ADEV_NODOORLOCK) 898 return (0); 899 900 xs = scsi_xs_get(sc_link, flags); 901 if (xs == NULL) 902 return (ENOMEM); 903 xs->cmdlen = sizeof(*cmd); 904 xs->retries = 2; 905 xs->timeout = 5000; 906 907 cmd = (struct scsi_prevent *)xs->cmd; 908 cmd->opcode = PREVENT_ALLOW; 909 cmd->how = type; 910 911 error = scsi_xs_sync(xs); 912 scsi_xs_put(xs); 913 914 return (error); 915 } 916 917 /* 918 * Get scsi driver to send a "start up" command 919 */ 920 int 921 scsi_start(struct scsi_link *sc_link, int type, int flags) 922 { 923 struct scsi_start_stop *cmd; 924 struct scsi_xfer *xs; 925 int error; 926 927 xs = scsi_xs_get(sc_link, flags); 928 if (xs == NULL) 929 return (ENOMEM); 930 xs->cmdlen = sizeof(*cmd); 931 xs->retries = 2; 932 xs->timeout = (type == SSS_START) ? 30000 : 10000; 933 934 cmd = (struct scsi_start_stop *)xs->cmd; 935 cmd->opcode = START_STOP; 936 cmd->how = type; 937 938 error = scsi_xs_sync(xs); 939 scsi_xs_put(xs); 940 941 return (error); 942 } 943 944 int 945 scsi_mode_sense(struct scsi_link *sc_link, int byte2, int page, 946 struct scsi_mode_header *data, size_t len, int flags, int timeout) 947 { 948 struct scsi_mode_sense *cmd; 949 struct scsi_xfer *xs; 950 int error; 951 952 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN); 953 if (xs == NULL) 954 return (ENOMEM); 955 xs->cmdlen = sizeof(*cmd); 956 xs->data = (void *)data; 957 xs->datalen = len; 958 xs->timeout = timeout; 959 960 /* 961 * Make sure the sense buffer is clean before we do the mode sense, so 962 * that checks for bogus values of 0 will work in case the mode sense 963 * fails. 964 */ 965 bzero(data, len); 966 967 cmd = (struct scsi_mode_sense *)xs->cmd; 968 cmd->opcode = MODE_SENSE; 969 cmd->byte2 = byte2; 970 cmd->page = page; 971 972 if (len > 0xff) 973 len = 0xff; 974 cmd->length = len; 975 976 error = scsi_xs_sync(xs); 977 scsi_xs_put(xs); 978 979 SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_sense: page %#x, error = %d\n", 980 page, error)); 981 982 return (error); 983 } 984 985 int 986 scsi_mode_sense_big(struct scsi_link *sc_link, int byte2, int page, 987 struct scsi_mode_header_big *data, size_t len, int flags, int timeout) 988 { 989 struct scsi_mode_sense_big *cmd; 990 struct scsi_xfer *xs; 991 int error; 992 993 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN); 994 if (xs == NULL) 995 return (ENOMEM); 996 xs->cmdlen = sizeof(*cmd); 997 xs->data = (void *)data; 998 xs->datalen = len; 999 xs->timeout = timeout; 1000 1001 /* 1002 * Make sure the sense buffer is clean before we do the mode sense, so 1003 * that checks for bogus values of 0 will work in case the mode sense 1004 * fails. 1005 */ 1006 bzero(data, len); 1007 1008 cmd = (struct scsi_mode_sense_big *)xs->cmd; 1009 cmd->opcode = MODE_SENSE_BIG; 1010 cmd->byte2 = byte2; 1011 cmd->page = page; 1012 1013 if (len > 0xffff) 1014 len = 0xffff; 1015 _lto2b(len, cmd->length); 1016 1017 error = scsi_xs_sync(xs); 1018 scsi_xs_put(xs); 1019 1020 SC_DEBUG(sc_link, SDEV_DB2, 1021 ("scsi_mode_sense_big: page %#x, error = %d\n", page, error)); 1022 1023 return (error); 1024 } 1025 1026 void * 1027 scsi_mode_sense_page(struct scsi_mode_header *hdr, const int page_len) 1028 { 1029 int total_length, header_length; 1030 1031 total_length = hdr->data_length + sizeof(hdr->data_length); 1032 header_length = sizeof(*hdr) + hdr->blk_desc_len; 1033 1034 if ((total_length - header_length) < page_len) 1035 return (NULL); 1036 1037 return ((u_char *)hdr + header_length); 1038 } 1039 1040 void * 1041 scsi_mode_sense_big_page(struct scsi_mode_header_big *hdr, const int page_len) 1042 { 1043 int total_length, header_length; 1044 1045 total_length = _2btol(hdr->data_length) + sizeof(hdr->data_length); 1046 header_length = sizeof(*hdr) + _2btol(hdr->blk_desc_len); 1047 1048 if ((total_length - header_length) < page_len) 1049 return (NULL); 1050 1051 return ((u_char *)hdr + header_length); 1052 } 1053 1054 int 1055 scsi_do_mode_sense(struct scsi_link *sc_link, int page, 1056 union scsi_mode_sense_buf *buf, void **page_data, u_int32_t *density, 1057 u_int64_t *block_count, u_int32_t *block_size, int page_len, int flags, 1058 int *big) 1059 { 1060 struct scsi_direct_blk_desc *direct; 1061 struct scsi_blk_desc *general; 1062 int error, blk_desc_len, offset; 1063 1064 *page_data = NULL; 1065 1066 if (density != NULL) 1067 *density = 0; 1068 if (block_count != NULL) 1069 *block_count = 0; 1070 if (block_size != NULL) 1071 *block_size = 0; 1072 if (big != NULL) 1073 *big = 0; 1074 1075 if ((sc_link->flags & SDEV_ATAPI) == 0 || 1076 (sc_link->inqdata.device & SID_TYPE) == T_SEQUENTIAL) { 1077 /* 1078 * Try 6 byte mode sense request first. Some devices don't 1079 * distinguish between 6 and 10 byte MODE SENSE commands, 1080 * returning 6 byte data for 10 byte requests. ATAPI tape 1081 * drives use MODE SENSE (6) even though ATAPI uses 10 byte 1082 * everything else. Don't bother with SMS_DBD. Check returned 1083 * data length to ensure that at least a header (3 additional 1084 * bytes) is returned. 1085 */ 1086 error = scsi_mode_sense(sc_link, 0, page, &buf->hdr, 1087 sizeof(*buf), flags, 20000); 1088 if (error == 0) { 1089 *page_data = scsi_mode_sense_page(&buf->hdr, page_len); 1090 if (*page_data == NULL) { 1091 /* 1092 * XXX 1093 * Page data may be invalid (e.g. all zeros) 1094 * but we accept the device's word that this is 1095 * the best it can do. Some devices will freak 1096 * out if their word is not accepted and 1097 * MODE_SENSE_BIG is attempted. 1098 */ 1099 return (0); 1100 } 1101 offset = sizeof(struct scsi_mode_header); 1102 blk_desc_len = buf->hdr.blk_desc_len; 1103 goto blk_desc; 1104 } 1105 } 1106 1107 /* 1108 * Try 10 byte mode sense request. Don't bother with SMS_DBD or 1109 * SMS_LLBAA. Bail out if the returned information is less than 1110 * a big header in size (6 additional bytes). 1111 */ 1112 if ((sc_link->flags & (SDEV_ATAPI | SDEV_UMASS)) == 0 && 1113 SCSISPC(sc_link->inqdata.version) < 2) { 1114 /* 1115 * The 10 byte MODE_SENSE request appeared with SCSI-2, 1116 * so don't bother trying it on SCSI-1 devices, they are 1117 * not supposed to understand it. 1118 */ 1119 return (0); 1120 } 1121 error = scsi_mode_sense_big(sc_link, 0, page, &buf->hdr_big, 1122 sizeof(*buf), flags, 20000); 1123 if (error != 0) 1124 return (error); 1125 if (_2btol(buf->hdr_big.data_length) < 6) 1126 return (EIO); 1127 1128 if (big != NULL) 1129 *big = 1; 1130 offset = sizeof(struct scsi_mode_header_big); 1131 *page_data = scsi_mode_sense_big_page(&buf->hdr_big, page_len); 1132 blk_desc_len = _2btol(buf->hdr_big.blk_desc_len); 1133 1134 blk_desc: 1135 /* Both scsi_blk_desc and scsi_direct_blk_desc are 8 bytes. */ 1136 if (blk_desc_len == 0 || (blk_desc_len % 8 != 0)) 1137 return (0); 1138 1139 switch (sc_link->inqdata.device & SID_TYPE) { 1140 case T_SEQUENTIAL: 1141 /* 1142 * XXX What other device types return general block descriptors? 1143 */ 1144 general = (struct scsi_blk_desc *)&buf->buf[offset]; 1145 if (density != NULL) 1146 *density = general->density; 1147 if (block_size != NULL) 1148 *block_size = _3btol(general->blklen); 1149 if (block_count != NULL) 1150 *block_count = (u_int64_t)_3btol(general->nblocks); 1151 break; 1152 1153 default: 1154 direct = (struct scsi_direct_blk_desc *)&buf->buf[offset]; 1155 if (density != NULL) 1156 *density = direct->density; 1157 if (block_size != NULL) 1158 *block_size = _3btol(direct->blklen); 1159 if (block_count != NULL) 1160 *block_count = (u_int64_t)_4btol(direct->nblocks); 1161 break; 1162 } 1163 1164 return (0); 1165 } 1166 1167 int 1168 scsi_mode_select(struct scsi_link *sc_link, int byte2, 1169 struct scsi_mode_header *data, int flags, int timeout) 1170 { 1171 struct scsi_mode_select *cmd; 1172 struct scsi_xfer *xs; 1173 u_int32_t len; 1174 int error; 1175 1176 len = data->data_length + 1; /* 1 == sizeof(data_length) */ 1177 1178 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_OUT); 1179 if (xs == NULL) 1180 return (ENOMEM); 1181 xs->cmdlen = sizeof(*cmd); 1182 xs->data = (void *)data; 1183 xs->datalen = len; 1184 xs->timeout = timeout; 1185 1186 cmd = (struct scsi_mode_select *)xs->cmd; 1187 cmd->opcode = MODE_SELECT; 1188 cmd->byte2 = byte2; 1189 cmd->length = len; 1190 1191 /* Length is reserved when doing mode select so zero it. */ 1192 data->data_length = 0; 1193 1194 error = scsi_xs_sync(xs); 1195 scsi_xs_put(xs); 1196 1197 SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_select: error = %d\n", error)); 1198 1199 return (error); 1200 } 1201 1202 int 1203 scsi_mode_select_big(struct scsi_link *sc_link, int byte2, 1204 struct scsi_mode_header_big *data, int flags, int timeout) 1205 { 1206 struct scsi_mode_select_big *cmd; 1207 struct scsi_xfer *xs; 1208 u_int32_t len; 1209 int error; 1210 1211 len = _2btol(data->data_length) + 2; /* 2 == sizeof data_length */ 1212 1213 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_OUT); 1214 if (xs == NULL) 1215 return (ENOMEM); 1216 xs->cmdlen = sizeof(*cmd); 1217 xs->data = (void *)data; 1218 xs->datalen = len; 1219 xs->timeout = timeout; 1220 1221 cmd = (struct scsi_mode_select_big *)xs->cmd; 1222 cmd->opcode = MODE_SELECT_BIG; 1223 cmd->byte2 = byte2; 1224 _lto2b(len, cmd->length); 1225 1226 /* Length is reserved when doing mode select so zero it. */ 1227 _lto2b(0, data->data_length); 1228 1229 error = scsi_xs_sync(xs); 1230 scsi_xs_put(xs); 1231 1232 SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_select_big: error = %d\n", 1233 error)); 1234 1235 return (error); 1236 } 1237 1238 int 1239 scsi_report_luns(struct scsi_link *sc_link, int selectreport, 1240 struct scsi_report_luns_data *data, u_int32_t datalen, int flags, 1241 int timeout) 1242 { 1243 struct scsi_report_luns *cmd; 1244 struct scsi_xfer *xs; 1245 int error; 1246 1247 xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN); 1248 if (xs == NULL) 1249 return (ENOMEM); 1250 xs->cmdlen = sizeof(*cmd); 1251 xs->data = (void *)data; 1252 xs->datalen = datalen; 1253 xs->timeout = timeout; 1254 1255 bzero(data, datalen); 1256 1257 cmd = (struct scsi_report_luns *)xs->cmd; 1258 cmd->opcode = REPORT_LUNS; 1259 cmd->selectreport = selectreport; 1260 _lto4b(datalen, cmd->length); 1261 1262 error = scsi_xs_sync(xs); 1263 scsi_xs_put(xs); 1264 1265 SC_DEBUG(sc_link, SDEV_DB2, ("scsi_report_luns: error = %d\n", error)); 1266 1267 return (error); 1268 } 1269 1270 void 1271 scsi_xs_exec(struct scsi_xfer *xs) 1272 { 1273 xs->error = XS_NOERROR; 1274 xs->resid = xs->datalen; 1275 xs->status = 0; 1276 CLR(xs->flags, ITSDONE); 1277 1278 #ifdef SCSIDEBUG 1279 if (xs->sc_link->flags & SDEV_DB1) { 1280 scsi_xs_show(xs); 1281 if (xs->datalen && (xs->flags & SCSI_DATA_OUT)) 1282 scsi_show_mem(xs->data, min(64, xs->datalen)); 1283 } 1284 #endif 1285 1286 /* The adapter's scsi_cmd() is responsible for calling scsi_done(). */ 1287 KERNEL_LOCK(); 1288 xs->sc_link->adapter->scsi_cmd(xs); 1289 KERNEL_UNLOCK(); 1290 } 1291 1292 /* 1293 * This routine is called by the adapter when its xs handling is done. 1294 */ 1295 void 1296 scsi_done(struct scsi_xfer *xs) 1297 { 1298 #ifdef SCSIDEBUG 1299 if (xs->sc_link->flags & SDEV_DB1) { 1300 if (xs->datalen && (xs->flags & SCSI_DATA_IN)) 1301 scsi_show_mem(xs->data, min(64, xs->datalen)); 1302 } 1303 #endif /* SCSIDEBUG */ 1304 1305 SET(xs->flags, ITSDONE); 1306 KERNEL_LOCK(); 1307 xs->done(xs); 1308 KERNEL_UNLOCK(); 1309 } 1310 1311 int 1312 scsi_xs_sync(struct scsi_xfer *xs) 1313 { 1314 struct mutex cookie = MUTEX_INITIALIZER(IPL_BIO); 1315 int error; 1316 1317 #ifdef DIAGNOSTIC 1318 if (xs->cookie != NULL) 1319 panic("xs->cookie != NULL in scsi_xs_sync"); 1320 if (xs->done != NULL) 1321 panic("xs->done != NULL in scsi_xs_sync"); 1322 #endif 1323 1324 /* 1325 * If we cant sleep while waiting for completion, get the adapter to 1326 * complete it for us. 1327 */ 1328 if (ISSET(xs->flags, SCSI_NOSLEEP)) 1329 SET(xs->flags, SCSI_POLL); 1330 1331 xs->done = scsi_xs_sync_done; 1332 1333 do { 1334 xs->cookie = &cookie; 1335 1336 scsi_xs_exec(xs); 1337 1338 mtx_enter(&cookie); 1339 while (xs->cookie != NULL) 1340 msleep(xs, &cookie, PRIBIO, "syncxs", 0); 1341 mtx_leave(&cookie); 1342 1343 error = scsi_xs_error(xs); 1344 } while (error == ERESTART); 1345 1346 return (error); 1347 } 1348 1349 void 1350 scsi_xs_sync_done(struct scsi_xfer *xs) 1351 { 1352 struct mutex *cookie = xs->cookie; 1353 1354 if (cookie == NULL) 1355 panic("scsi_done called twice on xs(%p)", xs); 1356 1357 mtx_enter(cookie); 1358 xs->cookie = NULL; 1359 if (!ISSET(xs->flags, SCSI_NOSLEEP)) 1360 wakeup_one(xs); 1361 mtx_leave(cookie); 1362 } 1363 1364 int 1365 scsi_xs_error(struct scsi_xfer *xs) 1366 { 1367 int error = EIO; 1368 1369 SC_DEBUG(xs->sc_link, SDEV_DB3, ("scsi_xs_error,err = 0x%x\n", 1370 xs->error)); 1371 1372 if (ISSET(xs->sc_link->state, SDEV_S_DYING)) 1373 return (ENXIO); 1374 1375 switch (xs->error) { 1376 case XS_NOERROR: /* nearly always hit this one */ 1377 error = 0; 1378 break; 1379 1380 case XS_SENSE: 1381 case XS_SHORTSENSE: 1382 #ifdef SCSIDEBUG 1383 scsi_sense_print_debug(xs); 1384 #endif 1385 error = xs->sc_link->interpret_sense(xs); 1386 SC_DEBUG(xs->sc_link, SDEV_DB3, 1387 ("scsi_interpret_sense returned %#x\n", error)); 1388 break; 1389 1390 case XS_NO_CCB: 1391 case XS_BUSY: 1392 error = scsi_delay(xs, 1); 1393 break; 1394 1395 case XS_TIMEOUT: 1396 case XS_RESET: 1397 error = ERESTART; 1398 break; 1399 1400 case XS_DRIVER_STUFFUP: 1401 case XS_SELTIMEOUT: 1402 break; 1403 1404 default: 1405 sc_print_addr(xs->sc_link); 1406 printf("unknown error category (0x%x) from scsi driver\n", 1407 xs->error); 1408 break; 1409 } 1410 1411 if (error == ERESTART && xs->retries-- < 1) 1412 return (EIO); 1413 else 1414 return (error); 1415 } 1416 1417 int 1418 scsi_delay(struct scsi_xfer *xs, int seconds) 1419 { 1420 switch (xs->flags & (SCSI_POLL | SCSI_NOSLEEP)) { 1421 case SCSI_POLL: 1422 delay(1000000 * seconds); 1423 return (ERESTART); 1424 case SCSI_NOSLEEP: 1425 /* Retry the command immediately since we can't delay. */ 1426 return (ERESTART); 1427 case (SCSI_POLL | SCSI_NOSLEEP): 1428 /* Invalid combination! */ 1429 return (EIO); 1430 } 1431 1432 while (seconds-- > 0) { 1433 if (tsleep(&lbolt, PRIBIO|PCATCH, "scbusy", 0)) { 1434 /* Signal == abort xs. */ 1435 return (EIO); 1436 } 1437 } 1438 1439 return (ERESTART); 1440 } 1441 1442 #ifdef SCSIDEBUG 1443 /* 1444 * Print out sense data details. 1445 */ 1446 void 1447 scsi_sense_print_debug(struct scsi_xfer *xs) 1448 { 1449 struct scsi_sense_data *sense = &xs->sense; 1450 struct scsi_link *sc_link = xs->sc_link; 1451 1452 SC_DEBUG(sc_link, SDEV_DB1, 1453 ("code:%#x valid:%d key:%#x ili:%d eom:%d fmark:%d extra:%d\n", 1454 sense->error_code & SSD_ERRCODE, 1455 sense->error_code & SSD_ERRCODE_VALID ? 1 : 0, 1456 sense->flags & SSD_KEY, 1457 sense->flags & SSD_ILI ? 1 : 0, 1458 sense->flags & SSD_EOM ? 1 : 0, 1459 sense->flags & SSD_FILEMARK ? 1 : 0, 1460 sense->extra_len)); 1461 1462 if (xs->sc_link->flags & SDEV_DB1) 1463 scsi_show_mem((u_char *)&xs->sense, sizeof(xs->sense)); 1464 1465 scsi_print_sense(xs); 1466 } 1467 #endif 1468 1469 /* 1470 * Look at the returned sense and act on the error, determining 1471 * the unix error number to pass back. (0 = report no error) 1472 * 1473 * THIS IS THE DEFAULT ERROR HANDLER 1474 */ 1475 int 1476 scsi_interpret_sense(struct scsi_xfer *xs) 1477 { 1478 struct scsi_sense_data *sense = &xs->sense; 1479 struct scsi_link *sc_link = xs->sc_link; 1480 u_int8_t serr, skey; 1481 int error; 1482 1483 /* Default sense interpretation. */ 1484 serr = sense->error_code & SSD_ERRCODE; 1485 if (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED) 1486 skey = 0xff; /* Invalid value, since key is 4 bit value. */ 1487 else 1488 skey = sense->flags & SSD_KEY; 1489 1490 /* 1491 * Interpret the key/asc/ascq information where appropriate. 1492 */ 1493 error = 0; 1494 switch (skey) { 1495 case SKEY_NO_SENSE: 1496 case SKEY_RECOVERED_ERROR: 1497 if (xs->resid == xs->datalen) 1498 xs->resid = 0; /* not short read */ 1499 break; 1500 case SKEY_BLANK_CHECK: 1501 case SKEY_EQUAL: 1502 break; 1503 case SKEY_NOT_READY: 1504 if ((xs->flags & SCSI_IGNORE_NOT_READY) != 0) 1505 return (0); 1506 error = EIO; 1507 if (xs->retries) { 1508 switch (ASC_ASCQ(sense)) { 1509 case SENSE_NOT_READY_BECOMING_READY: 1510 case SENSE_NOT_READY_FORMAT: 1511 case SENSE_NOT_READY_REBUILD: 1512 case SENSE_NOT_READY_RECALC: 1513 case SENSE_NOT_READY_INPROGRESS: 1514 case SENSE_NOT_READY_LONGWRITE: 1515 case SENSE_NOT_READY_SELFTEST: 1516 case SENSE_NOT_READY_INIT_REQUIRED: 1517 SC_DEBUG(sc_link, SDEV_DB1, 1518 ("not ready (ASC_ASCQ == %#x)\n", 1519 ASC_ASCQ(sense))); 1520 return (scsi_delay(xs, 1)); 1521 case SENSE_NOMEDIUM: 1522 case SENSE_NOMEDIUM_TCLOSED: 1523 case SENSE_NOMEDIUM_TOPEN: 1524 case SENSE_NOMEDIUM_LOADABLE: 1525 case SENSE_NOMEDIUM_AUXMEM: 1526 sc_link->flags &= ~SDEV_MEDIA_LOADED; 1527 error = ENOMEDIUM; 1528 break; 1529 default: 1530 break; 1531 } 1532 } 1533 break; 1534 case SKEY_MEDIUM_ERROR: 1535 switch (ASC_ASCQ(sense)) { 1536 case SENSE_NOMEDIUM: 1537 case SENSE_NOMEDIUM_TCLOSED: 1538 case SENSE_NOMEDIUM_TOPEN: 1539 case SENSE_NOMEDIUM_LOADABLE: 1540 case SENSE_NOMEDIUM_AUXMEM: 1541 sc_link->flags &= ~SDEV_MEDIA_LOADED; 1542 error = ENOMEDIUM; 1543 break; 1544 case SENSE_BAD_MEDIUM: 1545 case SENSE_NR_MEDIUM_UNKNOWN_FORMAT: 1546 case SENSE_NR_MEDIUM_INCOMPATIBLE_FORMAT: 1547 case SENSE_NW_MEDIUM_UNKNOWN_FORMAT: 1548 case SENSE_NW_MEDIUM_INCOMPATIBLE_FORMAT: 1549 case SENSE_NF_MEDIUM_INCOMPATIBLE_FORMAT: 1550 case SENSE_NW_MEDIUM_AC_MISMATCH: 1551 error = EMEDIUMTYPE; 1552 break; 1553 default: 1554 error = EIO; 1555 break; 1556 } 1557 break; 1558 case SKEY_ILLEGAL_REQUEST: 1559 if ((xs->flags & SCSI_IGNORE_ILLEGAL_REQUEST) != 0) 1560 return (0); 1561 if (ASC_ASCQ(sense) == SENSE_MEDIUM_REMOVAL_PREVENTED) 1562 return(EBUSY); 1563 error = EINVAL; 1564 break; 1565 case SKEY_UNIT_ATTENTION: 1566 switch (ASC_ASCQ(sense)) { 1567 case SENSE_POWER_RESET_OR_BUS: 1568 case SENSE_POWER_ON: 1569 case SENSE_BUS_RESET: 1570 case SENSE_BUS_DEVICE_RESET: 1571 case SENSE_DEVICE_INTERNAL_RESET: 1572 case SENSE_TSC_CHANGE_SE: 1573 case SENSE_TSC_CHANGE_LVD: 1574 case SENSE_IT_NEXUS_LOSS: 1575 return (scsi_delay(xs, 1)); 1576 default: 1577 break; 1578 } 1579 if ((sc_link->flags & SDEV_REMOVABLE) != 0) 1580 sc_link->flags &= ~SDEV_MEDIA_LOADED; 1581 if ((xs->flags & SCSI_IGNORE_MEDIA_CHANGE) != 0 || 1582 /* XXX Should reupload any transient state. */ 1583 (sc_link->flags & SDEV_REMOVABLE) == 0) { 1584 return (scsi_delay(xs, 1)); 1585 } 1586 error = EIO; 1587 break; 1588 case SKEY_WRITE_PROTECT: 1589 error = EROFS; 1590 break; 1591 case SKEY_ABORTED_COMMAND: 1592 error = ERESTART; 1593 break; 1594 case SKEY_VOLUME_OVERFLOW: 1595 error = ENOSPC; 1596 break; 1597 case SKEY_HARDWARE_ERROR: 1598 if (ASC_ASCQ(sense) == SENSE_CARTRIDGE_FAULT) 1599 return(EMEDIUMTYPE); 1600 error = EIO; 1601 break; 1602 default: 1603 error = EIO; 1604 break; 1605 } 1606 1607 #ifndef SCSIDEBUG 1608 /* SCSIDEBUG would mean it has already been printed. */ 1609 if (skey && (xs->flags & SCSI_SILENT) == 0) 1610 scsi_print_sense(xs); 1611 #endif /* SCSIDEBUG */ 1612 1613 return (error); 1614 } 1615 1616 /* 1617 * Utility routines often used in SCSI stuff 1618 */ 1619 1620 1621 /* 1622 * Print out the scsi_link structure's address info. 1623 */ 1624 void 1625 sc_print_addr(struct scsi_link *sc_link) 1626 { 1627 struct device *adapter_device = sc_link->bus->sc_dev.dv_parent; 1628 1629 printf("%s(%s:%d:%d): ", 1630 sc_link->device_softc ? 1631 ((struct device *)sc_link->device_softc)->dv_xname : "probe", 1632 adapter_device->dv_xname, 1633 sc_link->target, sc_link->lun); 1634 } 1635 1636 static const char *sense_keys[16] = { 1637 "No Additional Sense", 1638 "Soft Error", 1639 "Not Ready", 1640 "Media Error", 1641 "Hardware Error", 1642 "Illegal Request", 1643 "Unit Attention", 1644 "Write Protected", 1645 "Blank Check", 1646 "Vendor Unique", 1647 "Copy Aborted", 1648 "Aborted Command", 1649 "Equal Error", 1650 "Volume Overflow", 1651 "Miscompare Error", 1652 "Reserved" 1653 }; 1654 1655 #ifdef SCSITERSE 1656 static __inline void 1657 asc2ascii(u_int8_t asc, u_int8_t ascq, char *result, size_t len) 1658 { 1659 snprintf(result, len, "ASC 0x%02x ASCQ 0x%02x", asc, ascq); 1660 } 1661 #else 1662 static const struct { 1663 u_int8_t asc, ascq; 1664 char *description; 1665 } adesc[] = { 1666 /* www.t10.org/lists/asc-num.txt as of 11/15/10. */ 1667 { 0x00, 0x00, "No Additional Sense Information" }, 1668 { 0x00, 0x01, "Filemark Detected" }, 1669 { 0x00, 0x02, "End-Of-Partition/Medium Detected" }, 1670 { 0x00, 0x03, "Setmark Detected" }, 1671 { 0x00, 0x04, "Beginning-Of-Partition/Medium Detected" }, 1672 { 0x00, 0x05, "End-Of-Data Detected" }, 1673 { 0x00, 0x06, "I/O Process Terminated" }, 1674 { 0x00, 0x11, "Audio Play Operation In Progress" }, 1675 { 0x00, 0x12, "Audio Play Operation Paused" }, 1676 { 0x00, 0x13, "Audio Play Operation Successfully Completed" }, 1677 { 0x00, 0x14, "Audio Play Operation Stopped Due to Error" }, 1678 { 0x00, 0x15, "No Current Audio Status To Return" }, 1679 { 0x00, 0x16, "Operation In Progress" }, 1680 { 0x00, 0x17, "Cleaning Requested" }, 1681 { 0x00, 0x18, "Erase Operation In Progress" }, 1682 { 0x00, 0x19, "Locate Operation In Progress" }, 1683 { 0x00, 0x1A, "Rewind Operation In Progress" }, 1684 { 0x00, 0x1B, "Set Capacity Operation In Progress" }, 1685 { 0x00, 0x1C, "Verify Operation In Progress" }, 1686 { 0x01, 0x00, "No Index/Sector Signal" }, 1687 { 0x02, 0x00, "No Seek Complete" }, 1688 { 0x03, 0x00, "Peripheral Device Write Fault" }, 1689 { 0x03, 0x01, "No Write Current" }, 1690 { 0x03, 0x02, "Excessive Write Errors" }, 1691 { 0x04, 0x00, "Logical Unit Not Ready, Cause Not Reportable" }, 1692 { 0x04, 0x01, "Logical Unit Is in Process Of Becoming Ready" }, 1693 { 0x04, 0x02, "Logical Unit Not Ready, Initialization Command Required" }, 1694 { 0x04, 0x03, "Logical Unit Not Ready, Manual Intervention Required" }, 1695 { 0x04, 0x04, "Logical Unit Not Ready, Format In Progress" }, 1696 { 0x04, 0x05, "Logical Unit Not Ready, Rebuild In Progress" }, 1697 { 0x04, 0x06, "Logical Unit Not Ready, Recalculation In Progress" }, 1698 { 0x04, 0x07, "Logical Unit Not Ready, Operation In Progress" }, 1699 { 0x04, 0x08, "Logical Unit Not Ready, Long Write In Progress" }, 1700 { 0x04, 0x09, "Logical Unit Not Ready, Self-Test In Progress" }, 1701 { 0x04, 0x0A, "Logical Unit Not Accessible, Asymmetric Access State Transition" }, 1702 { 0x04, 0x0B, "Logical Unit Not Accessible, Target Port In Standby State" }, 1703 { 0x04, 0x0C, "Logical Unit Not Accessible, Target Port In Unavailable State" }, 1704 { 0x04, 0x0D, "Logical Unit Not Ready, Structure Check Required" }, 1705 { 0x04, 0x10, "Logical Unit Not Ready, Auxiliary Memory Not Accessible" }, 1706 { 0x04, 0x11, "Logical Unit Not Ready, Notify (Enable Spinup) Required" }, 1707 { 0x04, 0x12, "Logical Unit Not Ready, Offline" }, 1708 { 0x04, 0x13, "Logical Unit Not Ready, SA Creation In Progress" }, 1709 { 0x04, 0x14, "Logical Unit Not Ready, Space Allocation In Progress" }, 1710 { 0x04, 0x15, "Logical Unit Not Ready, Robotics Disabled" }, 1711 { 0x04, 0x16, "Logical Unit Not Ready, Configuration Required" }, 1712 { 0x04, 0x17, "Logical Unit Not Ready, Calibration Required" }, 1713 { 0x04, 0x18, "Logical Unit Not Ready, A Door Is Open" }, 1714 { 0x04, 0x19, "Logical Unit Not Ready, Operating In Sequential Mode" }, 1715 { 0x04, 0x1A, "Logical Unit Not Ready, Start Stop Unit Command In Progress" }, 1716 { 0x05, 0x00, "Logical Unit Does Not Respond To Selection" }, 1717 { 0x06, 0x00, "No Reference Position Found" }, 1718 { 0x07, 0x00, "Multiple Peripheral Devices Selected" }, 1719 { 0x08, 0x00, "Logical Unit Communication Failure" }, 1720 { 0x08, 0x01, "Logical Unit Communication Timeout" }, 1721 { 0x08, 0x02, "Logical Unit Communication Parity Error" }, 1722 { 0x08, 0x03, "Logical Unit Communication CRC Error (ULTRA-DMA/32)" }, 1723 { 0x08, 0x04, "Unreachable Copy Target" }, 1724 { 0x09, 0x00, "Track Following Error" }, 1725 { 0x09, 0x01, "Tracking Servo Failure" }, 1726 { 0x09, 0x02, "Focus Servo Failure" }, 1727 { 0x09, 0x03, "Spindle Servo Failure" }, 1728 { 0x09, 0x04, "Head Select Fault" }, 1729 { 0x0A, 0x00, "Error Log Overflow" }, 1730 { 0x0B, 0x00, "Warning" }, 1731 { 0x0B, 0x01, "Warning - Specified Temperature Exceeded" }, 1732 { 0x0B, 0x02, "Warning - Enclosure Degraded" }, 1733 { 0x0B, 0x03, "Warning - Background Self-Test Failed" }, 1734 { 0x0B, 0x04, "Warning - Background Pre-Scan Detected Medium Error" }, 1735 { 0x0B, 0x05, "Warning - Background Medium Scan Detected Medium Error" }, 1736 { 0x0B, 0x06, "Warning - Non-Volatile Cache Now Volatile" }, 1737 { 0x0B, 0x07, "Warning - Degraded Power To Non-Volatile Cache" }, 1738 { 0x0B, 0x08, "Warning - Power Loss Expected" }, 1739 { 0x0C, 0x00, "Write Error" }, 1740 { 0x0C, 0x01, "Write Error Recovered with Auto Reallocation" }, 1741 { 0x0C, 0x02, "Write Error - Auto Reallocate Failed" }, 1742 { 0x0C, 0x03, "Write Error - Recommend Reassignment" }, 1743 { 0x0C, 0x04, "Compression Check Miscompare Error" }, 1744 { 0x0C, 0x05, "Data Expansion Occurred During Compression" }, 1745 { 0x0C, 0x06, "Block Not Compressible" }, 1746 { 0x0C, 0x07, "Write Error - Recovery Needed" }, 1747 { 0x0C, 0x08, "Write Error - Recovery Failed" }, 1748 { 0x0C, 0x09, "Write Error - Loss Of Streaming" }, 1749 { 0x0C, 0x0A, "Write Error - Padding Blocks Added" }, 1750 { 0x0C, 0x0B, "Auxiliary Memory Write Error" }, 1751 { 0x0C, 0x0C, "Write Error - Unexpected Unsolicited Data" }, 1752 { 0x0C, 0x0D, "Write Error - Not Enough Unsolicited Data" }, 1753 { 0x0C, 0x0F, "Defects In Error Window" }, 1754 { 0x0D, 0x00, "Error Detected By Third Party Temporary Initiator" }, 1755 { 0x0D, 0x01, "Third Party Device Failure" }, 1756 { 0x0D, 0x02, "Copy Target Device Not Reachable" }, 1757 { 0x0D, 0x03, "Incorrect Copy Target Device Type" }, 1758 { 0x0D, 0x04, "Copy Target Device Data Underrun" }, 1759 { 0x0D, 0x05, "Copy Target Device Data Overrun" }, 1760 { 0x0E, 0x00, "Invalid Information Unit" }, 1761 { 0x0E, 0x01, "Information Unit Too Short" }, 1762 { 0x0E, 0x02, "Information Unit Too Long" }, 1763 { 0x10, 0x00, "ID CRC Or ECC Error" }, 1764 { 0x10, 0x01, "Logical Block Guard Check Failed" }, 1765 { 0x10, 0x02, "Logical Block Application Tag Check Failed" }, 1766 { 0x10, 0x03, "Logical Block Reference Tag Check Failed" }, 1767 { 0x10, 0x04, "Logical Block Protection Error On Recover Buffered Data" }, 1768 { 0x10, 0x05, "Logical Block Protection Method Error" }, 1769 { 0x11, 0x00, "Unrecovered Read Error" }, 1770 { 0x11, 0x01, "Read Retries Exhausted" }, 1771 { 0x11, 0x02, "Error Too Long To Correct" }, 1772 { 0x11, 0x03, "Multiple Read Errors" }, 1773 { 0x11, 0x04, "Unrecovered Read Error - Auto Reallocate Failed" }, 1774 { 0x11, 0x05, "L-EC Uncorrectable Error" }, 1775 { 0x11, 0x06, "CIRC Unrecovered Error" }, 1776 { 0x11, 0x07, "Data Resynchronization Error" }, 1777 { 0x11, 0x08, "Incomplete Block Read" }, 1778 { 0x11, 0x09, "No Gap Found" }, 1779 { 0x11, 0x0A, "Miscorrected Error" }, 1780 { 0x11, 0x0B, "Uncorrected Read Error - Recommend Reassignment" }, 1781 { 0x11, 0x0C, "Uncorrected Read Error - Recommend Rewrite The Data" }, 1782 { 0x11, 0x0D, "De-Compression CRC Error" }, 1783 { 0x11, 0x0E, "Cannot Decompress Using Declared Algorithm" }, 1784 { 0x11, 0x0F, "Error Reading UPC/EAN Number" }, 1785 { 0x11, 0x10, "Error Reading ISRC Number" }, 1786 { 0x11, 0x11, "Read Error - Loss Of Streaming" }, 1787 { 0x11, 0x12, "Auxiliary Memory Read Error" }, 1788 { 0x11, 0x13, "Read Error - Failed Retransmission Request" }, 1789 { 0x11, 0x14, "Read Error - LBA Marked Bad By Application Client" }, 1790 { 0x12, 0x00, "Address Mark Not Found for ID Field" }, 1791 { 0x13, 0x00, "Address Mark Not Found for Data Field" }, 1792 { 0x14, 0x00, "Recorded Entity Not Found" }, 1793 { 0x14, 0x01, "Record Not Found" }, 1794 { 0x14, 0x02, "Filemark or Setmark Not Found" }, 1795 { 0x14, 0x03, "End-Of-Data Not Found" }, 1796 { 0x14, 0x04, "Block Sequence Error" }, 1797 { 0x14, 0x05, "Record Not Found - Recommend Reassignment" }, 1798 { 0x14, 0x06, "Record Not Found - Data Auto-Reallocated" }, 1799 { 0x14, 0x07, "Locate Operation Failure" }, 1800 { 0x15, 0x00, "Random Positioning Error" }, 1801 { 0x15, 0x01, "Mechanical Positioning Error" }, 1802 { 0x15, 0x02, "Positioning Error Detected By Read of Medium" }, 1803 { 0x16, 0x00, "Data Synchronization Mark Error" }, 1804 { 0x16, 0x01, "Data Sync Error - Data Rewritten" }, 1805 { 0x16, 0x02, "Data Sync Error - Recommend Rewrite" }, 1806 { 0x16, 0x03, "Data Sync Error - Data Auto-Reallocated" }, 1807 { 0x16, 0x04, "Data Sync Error - Recommend Reassignment" }, 1808 { 0x17, 0x00, "Recovered Data With No Error Correction Applied" }, 1809 { 0x17, 0x01, "Recovered Data With Retries" }, 1810 { 0x17, 0x02, "Recovered Data With Positive Head Offset" }, 1811 { 0x17, 0x03, "Recovered Data With Negative Head Offset" }, 1812 { 0x17, 0x04, "Recovered Data With Retries and/or CIRC Applied" }, 1813 { 0x17, 0x05, "Recovered Data Using Previous Sector ID" }, 1814 { 0x17, 0x06, "Recovered Data Without ECC - Data Auto-Reallocated" }, 1815 { 0x17, 0x07, "Recovered Data Without ECC - Recommend Reassignment" }, 1816 { 0x17, 0x08, "Recovered Data Without ECC - Recommend Rewrite" }, 1817 { 0x17, 0x09, "Recovered Data Without ECC - Data Rewritten" }, 1818 { 0x18, 0x00, "Recovered Data With Error Correction Applied" }, 1819 { 0x18, 0x01, "Recovered Data With Error Correction & Retries Applied" }, 1820 { 0x18, 0x02, "Recovered Data - Data Auto-Reallocated" }, 1821 { 0x18, 0x03, "Recovered Data With CIRC" }, 1822 { 0x18, 0x04, "Recovered Data With L-EC" }, 1823 { 0x18, 0x05, "Recovered Data - Recommend Reassignment" }, 1824 { 0x18, 0x06, "Recovered Data - Recommend Rewrite" }, 1825 { 0x18, 0x07, "Recovered Data With ECC - Data Rewritten" }, 1826 { 0x18, 0x08, "Recovered Data With Linking" }, 1827 { 0x19, 0x00, "Defect List Error" }, 1828 { 0x19, 0x01, "Defect List Not Available" }, 1829 { 0x19, 0x02, "Defect List Error in Primary List" }, 1830 { 0x19, 0x03, "Defect List Error in Grown List" }, 1831 { 0x1A, 0x00, "Parameter List Length Error" }, 1832 { 0x1B, 0x00, "Synchronous Data Transfer Error" }, 1833 { 0x1C, 0x00, "Defect List Not Found" }, 1834 { 0x1C, 0x01, "Primary Defect List Not Found" }, 1835 { 0x1C, 0x02, "Grown Defect List Not Found" }, 1836 { 0x1D, 0x00, "Miscompare During Verify Operation" }, 1837 { 0x1D, 0x01, "Miscompare Verify Of Unmapped Lba" }, 1838 { 0x1E, 0x00, "Recovered ID with ECC" }, 1839 { 0x1F, 0x00, "Partial Defect List Transfer" }, 1840 { 0x20, 0x00, "Invalid Command Operation Code" }, 1841 { 0x20, 0x01, "Access Denied - Initiator Pending-Enrolled" }, 1842 { 0x20, 0x02, "Access Denied - No Access rights" }, 1843 { 0x20, 0x03, "Access Denied - Invalid Mgmt ID Key" }, 1844 { 0x20, 0x04, "Illegal Command While In Write Capable State" }, 1845 { 0x20, 0x05, "Obsolete" }, 1846 { 0x20, 0x06, "Illegal Command While In Explicit Address Mode" }, 1847 { 0x20, 0x07, "Illegal Command While In Implicit Address Mode" }, 1848 { 0x20, 0x08, "Access Denied - Enrollment Conflict" }, 1849 { 0x20, 0x09, "Access Denied - Invalid LU Identifier" }, 1850 { 0x20, 0x0A, "Access Denied - Invalid Proxy Token" }, 1851 { 0x20, 0x0B, "Access Denied - ACL LUN Conflict" }, 1852 { 0x20, 0x0C, "Illegal Command When Not In Append-Only Mode" }, 1853 { 0x21, 0x00, "Logical Block Address Out of Range" }, 1854 { 0x21, 0x01, "Invalid Element Address" }, 1855 { 0x21, 0x02, "Invalid Address For Write" }, 1856 { 0x21, 0x03, "Invalid Write Crossing Layer Jump" }, 1857 { 0x22, 0x00, "Illegal Function (Should 20 00, 24 00, or 26 00)" }, 1858 { 0x24, 0x00, "Illegal Field in CDB" }, 1859 { 0x24, 0x01, "CDB Decryption Error" }, 1860 { 0x24, 0x02, "Obsolete" }, 1861 { 0x24, 0x03, "Obsolete" }, 1862 { 0x24, 0x04, "Security Audit Value Frozen" }, 1863 { 0x24, 0x05, "Security Working Key Frozen" }, 1864 { 0x24, 0x06, "Nonce Not Unique" }, 1865 { 0x24, 0x07, "Nonce Timestamp Out Of Range" }, 1866 { 0x24, 0x08, "Invalid XCDB" }, 1867 { 0x25, 0x00, "Logical Unit Not Supported" }, 1868 { 0x26, 0x00, "Invalid Field In Parameter List" }, 1869 { 0x26, 0x01, "Parameter Not Supported" }, 1870 { 0x26, 0x02, "Parameter Value Invalid" }, 1871 { 0x26, 0x03, "Threshold Parameters Not Supported" }, 1872 { 0x26, 0x04, "Invalid Release Of Persistent Reservation" }, 1873 { 0x26, 0x05, "Data Decryption Error" }, 1874 { 0x26, 0x06, "Too Many Target Descriptors" }, 1875 { 0x26, 0x07, "Unsupported Target Descriptor Type Code" }, 1876 { 0x26, 0x08, "Too Many Segment Descriptors" }, 1877 { 0x26, 0x09, "Unsupported Segment Descriptor Type Code" }, 1878 { 0x26, 0x0A, "Unexpected Inexact Segment" }, 1879 { 0x26, 0x0B, "Inline Data Length Exceeded" }, 1880 { 0x26, 0x0C, "Invalid Operation For Copy Source Or Destination" }, 1881 { 0x26, 0x0D, "Copy Segment Granularity Violation" }, 1882 { 0x26, 0x0E, "Invalid Parameter While Port Is Enabled" }, 1883 { 0x26, 0x0F, "Invalid Data-Out Buffer Integrity Check Value" }, 1884 { 0x26, 0x10, "Data Decryption Key Fail Limit Reached" }, 1885 { 0x26, 0x11, "Incomplete Key-Associated Data Set" }, 1886 { 0x26, 0x12, "Vendor Specific Key Reference Not Found" }, 1887 { 0x27, 0x00, "Write Protected" }, 1888 { 0x27, 0x01, "Hardware Write Protected" }, 1889 { 0x27, 0x02, "Logical Unit Software Write Protected" }, 1890 { 0x27, 0x03, "Associated Write Protect" }, 1891 { 0x27, 0x04, "Persistent Write Protect" }, 1892 { 0x27, 0x05, "Permanent Write Protect" }, 1893 { 0x27, 0x06, "Conditional Write Protect" }, 1894 { 0x27, 0x07, "Space Allocation Failed Write Protect" }, 1895 { 0x28, 0x00, "Not Ready To Ready Transition (Medium May Have Changed)" }, 1896 { 0x28, 0x01, "Import Or Export Element Accessed" }, 1897 { 0x28, 0x02, "Format-Layer May Have Changed" }, 1898 { 0x28, 0x03, "Import/Export Element Accessed, Medium Changed" }, 1899 { 0x29, 0x00, "Power On, Reset, or Bus Device Reset Occurred" }, 1900 { 0x29, 0x01, "Power On Occurred" }, 1901 { 0x29, 0x02, "SCSI Bus Reset Occurred" }, 1902 { 0x29, 0x03, "Bus Device Reset Function Occurred" }, 1903 { 0x29, 0x04, "Device Internal Reset" }, 1904 { 0x29, 0x05, "Transceiver Mode Changed to Single Ended" }, 1905 { 0x29, 0x06, "Transceiver Mode Changed to LVD" }, 1906 { 0x29, 0x07, "I_T Nexus Loss Occurred" }, 1907 { 0x2A, 0x00, "Parameters Changed" }, 1908 { 0x2A, 0x01, "Mode Parameters Changed" }, 1909 { 0x2A, 0x02, "Log Parameters Changed" }, 1910 { 0x2A, 0x03, "Reservations Preempted" }, 1911 { 0x2A, 0x04, "Reservations Released" }, 1912 { 0x2A, 0x05, "Registrations Preempted" }, 1913 { 0x2A, 0x06, "Asymmetric Access State Changed" }, 1914 { 0x2A, 0x07, "Implicit Asymmetric Access State Transition Failed" }, 1915 { 0x2A, 0x08, "Priority Changed" }, 1916 { 0x2A, 0x09, "Capacity Data Has Changed" }, 1917 { 0x2A, 0x0A, "Error History I_T Nexus Cleared" }, 1918 { 0x2A, 0x0B, "Error History Snapshot Released" }, 1919 { 0x2A, 0x0C, "Error Recovery Attributes Have Changed" }, 1920 { 0x2A, 0x0D, "Data Encryption Capabilities Changed" }, 1921 { 0x2A, 0x10, "Timestamp Changed" }, 1922 { 0x2A, 0x11, "Data Encryption Parameters Changed By Another I_T Nexus" }, 1923 { 0x2A, 0x12, "Data Encryption Parameters Changed By Vendor Specific Event" }, 1924 { 0x2A, 0x13, "Data Encryption Key Instance Counter Has Changed" }, 1925 { 0x2A, 0x14, "SA Creation Capabilities Data Has Changed" }, 1926 { 0x2B, 0x00, "Copy Cannot Execute Since Host Cannot Disconnect" }, 1927 { 0x2C, 0x00, "Command Sequence Error" }, 1928 { 0x2C, 0x01, "Too Many Windows Specified" }, 1929 { 0x2C, 0x02, "Invalid Combination of Windows Specified" }, 1930 { 0x2C, 0x03, "Current Program Area Is Not Empty" }, 1931 { 0x2C, 0x04, "Current Program Area Is Empty" }, 1932 { 0x2C, 0x05, "Illegal Power Condition Request" }, 1933 { 0x2C, 0x06, "Persistent Prevent Conflict" }, 1934 { 0x2C, 0x07, "Previous Busy Status" }, 1935 { 0x2C, 0x08, "Previous Task Set Full Status" }, 1936 { 0x2C, 0x09, "Previous Reservation Conflict Status" }, 1937 { 0x2C, 0x0A, "Partition Or Collection Contains User Objects" }, 1938 { 0x2C, 0x0B, "Not Reserved" }, 1939 { 0x2C, 0x0C, "ORWrite Generation Does Not Match" }, 1940 { 0x2D, 0x00, "Overwrite Error On Update In Place" }, 1941 { 0x2E, 0x00, "Insufficient Time For Operation" }, 1942 { 0x2F, 0x00, "Commands Cleared By Another Initiator" }, 1943 { 0x2F, 0x01, "Commands Cleared By Power Loss Notification" }, 1944 { 0x2F, 0x02, "Commands Cleared By Device Server" }, 1945 { 0x30, 0x00, "Incompatible Medium Installed" }, 1946 { 0x30, 0x01, "Cannot Read Medium - Unknown Format" }, 1947 { 0x30, 0x02, "Cannot Read Medium - Incompatible Format" }, 1948 { 0x30, 0x03, "Cleaning Cartridge Installed" }, 1949 { 0x30, 0x04, "Cannot Write Medium - Unknown Format" }, 1950 { 0x30, 0x05, "Cannot Write Medium - Incompatible Format" }, 1951 { 0x30, 0x06, "Cannot Format Medium - Incompatible Medium" }, 1952 { 0x30, 0x07, "Cleaning Failure" }, 1953 { 0x30, 0x08, "Cannot Write - Application Code Mismatch" }, 1954 { 0x30, 0x09, "Current Session Not Fixated For Append" }, 1955 { 0x30, 0x0A, "Cleaning Request Rejected" }, 1956 { 0x30, 0x10, "Medium Not Formatted" }, 1957 { 0x30, 0x11, "Incompatible Volume Type" }, 1958 { 0x30, 0x12, "Incompatible Volume Qualifier" }, 1959 { 0x30, 0x13, "Cleaning Volume Expired" }, 1960 { 0x31, 0x00, "Medium Format Corrupted" }, 1961 { 0x31, 0x01, "Format Command Failed" }, 1962 { 0x31, 0x02, "Zoned Formatting Failed Due To Spare Linking" }, 1963 { 0x32, 0x00, "No Defect Spare Location Available" }, 1964 { 0x32, 0x01, "Defect List Update Failure" }, 1965 { 0x33, 0x00, "Tape Length Error" }, 1966 { 0x34, 0x00, "Enclosure Failure" }, 1967 { 0x35, 0x00, "Enclosure Services Failure" }, 1968 { 0x35, 0x01, "Unsupported Enclosure Function" }, 1969 { 0x35, 0x02, "Enclosure Services Unavailable" }, 1970 { 0x35, 0x03, "Enclosure Services Transfer Failure" }, 1971 { 0x35, 0x04, "Enclosure Services Transfer Refused" }, 1972 { 0x36, 0x00, "Ribbon, Ink, or Toner Failure" }, 1973 { 0x37, 0x00, "Rounded Parameter" }, 1974 { 0x38, 0x00, "Event Status Notification" }, 1975 { 0x38, 0x02, "ESN - Power Management Class Event" }, 1976 { 0x38, 0x04, "ESN - Media Class Event" }, 1977 { 0x38, 0x06, "ESN - Device Busy Class Event" }, 1978 { 0x39, 0x00, "Saving Parameters Not Supported" }, 1979 { 0x3A, 0x00, "Medium Not Present" }, 1980 { 0x3A, 0x01, "Medium Not Present - Tray Closed" }, 1981 { 0x3A, 0x02, "Medium Not Present - Tray Open" }, 1982 { 0x3A, 0x03, "Medium Not Present - Loadable" }, 1983 { 0x3A, 0x04, "Medium Not Present - Medium Auxiliary Memory Accessible" }, 1984 { 0x3B, 0x00, "Sequential Positioning Error" }, 1985 { 0x3B, 0x01, "Tape Position Error At Beginning-of-Medium" }, 1986 { 0x3B, 0x02, "Tape Position Error At End-of-Medium" }, 1987 { 0x3B, 0x03, "Tape or Electronic Vertical Forms Unit Not Ready" }, 1988 { 0x3B, 0x04, "Slew Failure" }, 1989 { 0x3B, 0x05, "Paper Jam" }, 1990 { 0x3B, 0x06, "Failed To Sense Top-Of-Form" }, 1991 { 0x3B, 0x07, "Failed To Sense Bottom-Of-Form" }, 1992 { 0x3B, 0x08, "Reposition Error" }, 1993 { 0x3B, 0x09, "Read Past End Of Medium" }, 1994 { 0x3B, 0x0A, "Read Past Beginning Of Medium" }, 1995 { 0x3B, 0x0B, "Position Past End Of Medium" }, 1996 { 0x3B, 0x0C, "Position Past Beginning Of Medium" }, 1997 { 0x3B, 0x0D, "Medium Destination Element Full" }, 1998 { 0x3B, 0x0E, "Medium Source Element Empty" }, 1999 { 0x3B, 0x0F, "End Of Medium Reached" }, 2000 { 0x3B, 0x11, "Medium Magazine Not Accessible" }, 2001 { 0x3B, 0x12, "Medium Magazine Removed" }, 2002 { 0x3B, 0x13, "Medium Magazine Inserted" }, 2003 { 0x3B, 0x14, "Medium Magazine Locked" }, 2004 { 0x3B, 0x15, "Medium Magazine Unlocked" }, 2005 { 0x3B, 0x16, "Mechanical Positioning Or Changer Error" }, 2006 { 0x3B, 0x17, "Read Past End Of User Object" }, 2007 { 0x3B, 0x18, "Element Disabled" }, 2008 { 0x3B, 0x19, "Element Enabled" }, 2009 { 0x3B, 0x1A, "Data Transfer Device Removed" }, 2010 { 0x3B, 0x1B, "Data Transfer Device Inserted" }, 2011 { 0x3D, 0x00, "Invalid Bits In IDENTIFY Message" }, 2012 { 0x3E, 0x00, "Logical Unit Has Not Self-Configured Yet" }, 2013 { 0x3E, 0x01, "Logical Unit Failure" }, 2014 { 0x3E, 0x02, "Timeout On Logical Unit" }, 2015 { 0x3E, 0x03, "Logical Unit Failed Self-Test" }, 2016 { 0x3E, 0x04, "Logical Unit Unable To Update Self-Test Log" }, 2017 { 0x3F, 0x00, "Target Operating Conditions Have Changed" }, 2018 { 0x3F, 0x01, "Microcode Has Changed" }, 2019 { 0x3F, 0x02, "Changed Operating Definition" }, 2020 { 0x3F, 0x03, "INQUIRY Data Has Changed" }, 2021 { 0x3F, 0x04, "component Device Attached" }, 2022 { 0x3F, 0x05, "Device Identifier Changed" }, 2023 { 0x3F, 0x06, "Redundancy Group Created Or Modified" }, 2024 { 0x3F, 0x07, "Redundancy Group Deleted" }, 2025 { 0x3F, 0x08, "Spare Created Or Modified" }, 2026 { 0x3F, 0x09, "Spare Deleted" }, 2027 { 0x3F, 0x0A, "Volume Set Created Or Modified" }, 2028 { 0x3F, 0x0B, "Volume Set Deleted" }, 2029 { 0x3F, 0x0C, "Volume Set Deassigned" }, 2030 { 0x3F, 0x0D, "Volume Set Reassigned" }, 2031 { 0x3F, 0x0E, "Reported LUNs Data Has Changed" }, 2032 { 0x3F, 0x0F, "Echo Buffer Overwritten" }, 2033 { 0x3F, 0x10, "Medium Loadable" }, 2034 { 0x3F, 0x11, "Medium Auxiliary Memory Accessible" }, 2035 { 0x3F, 0x12, "iSCSI IP Address Added" }, 2036 { 0x3F, 0x13, "iSCSI IP Address Removed" }, 2037 { 0x3F, 0x14, "iSCSI IP Address Changed" }, 2038 { 0x40, 0x00, "RAM FAILURE (Should Use 40 NN)" }, 2039 /* 2040 * ASC 0x40 also has an ASCQ range from 0x80 to 0xFF. 2041 * 0x40 0xNN DIAGNOSTIC FAILURE ON COMPONENT NN 2042 */ 2043 { 0x41, 0x00, "Data Path FAILURE (Should Use 40 NN)" }, 2044 { 0x42, 0x00, "Power-On or Self-Test FAILURE (Should Use 40 NN)" }, 2045 { 0x43, 0x00, "Message Error" }, 2046 { 0x44, 0x00, "Internal Target Failure" }, 2047 { 0x44, 0x71, "ATA Device Failed Set Features" }, 2048 { 0x45, 0x00, "Select Or Reselect Failure" }, 2049 { 0x46, 0x00, "Unsuccessful Soft Reset" }, 2050 { 0x47, 0x00, "SCSI Parity Error" }, 2051 { 0x47, 0x01, "Data Phase CRC Error Detected" }, 2052 { 0x47, 0x02, "SCSI Parity Error Detected During ST Data Phase" }, 2053 { 0x47, 0x03, "Information Unit iuCRC Error Detected" }, 2054 { 0x47, 0x04, "Asynchronous Information Protection Error Detected" }, 2055 { 0x47, 0x05, "Protocol Service CRC Error" }, 2056 { 0x47, 0x06, "PHY Test Function In Progress" }, 2057 { 0x47, 0x7F, "Some Commands Cleared By iSCSI Protocol Event" }, 2058 { 0x48, 0x00, "Initiator Detected Error Message Received" }, 2059 { 0x49, 0x00, "Invalid Message Error" }, 2060 { 0x4A, 0x00, "Command Phase Error" }, 2061 { 0x4B, 0x00, "Data Phase Error" }, 2062 { 0x4B, 0x01, "Invalid Target Port Transfer Tag Received" }, 2063 { 0x4B, 0x02, "Too Much Write Data" }, 2064 { 0x4B, 0x03, "ACK/NAK Timeout" }, 2065 { 0x4B, 0x04, "NAK Received" }, 2066 { 0x4B, 0x05, "Data Offset Error" }, 2067 { 0x4B, 0x06, "Initiator Response Timeout" }, 2068 { 0x4B, 0x07, "Connection Lost" }, 2069 { 0x4C, 0x00, "Logical Unit Failed Self-Configuration" }, 2070 /* 2071 * ASC 0x4D has an ASCQ range from 0x00 to 0xFF. 2072 * 0x4D 0xNN TAGGED OVERLAPPED COMMANDS (NN = TASK TAG) 2073 */ 2074 { 0x4E, 0x00, "Overlapped Commands Attempted" }, 2075 { 0x50, 0x00, "Write Append Error" }, 2076 { 0x50, 0x01, "Write Append Position Error" }, 2077 { 0x50, 0x02, "Position Error Related To Timing" }, 2078 { 0x51, 0x00, "Erase Failure" }, 2079 { 0x51, 0x01, "Erase Failure - Incomplete Erase Operation Detected" }, 2080 { 0x52, 0x00, "Cartridge Fault" }, 2081 { 0x53, 0x00, "Media Load or Eject Failed" }, 2082 { 0x53, 0x01, "Unload Tape Failure" }, 2083 { 0x53, 0x02, "Medium Removal Prevented" }, 2084 { 0x53, 0x03, "Medium Removal Prevented By Data Transfer Element" }, 2085 { 0x53, 0x04, "Medium Thread Or Unthread Failure" }, 2086 { 0x53, 0x05, "Volume Identifier Invalid" }, 2087 { 0x53, 0x06, "Volume Identifier Missing" }, 2088 { 0x53, 0x07, "Duplicate Volume Identifier" }, 2089 { 0x53, 0x08, "Element Status Unknown" }, 2090 { 0x54, 0x00, "SCSI To Host System Interface Failure" }, 2091 { 0x55, 0x00, "System Resource Failure" }, 2092 { 0x55, 0x01, "System Buffer Full" }, 2093 { 0x55, 0x02, "Insufficient Reservation Resources" }, 2094 { 0x55, 0x03, "Insufficient Resources" }, 2095 { 0x55, 0x04, "Insufficient Registration Resources" }, 2096 { 0x55, 0x05, "Insufficient Access Control Resources" }, 2097 { 0x55, 0x06, "Auxiliary Memory Out Of Space" }, 2098 { 0x55, 0x07, "Quota Error" }, 2099 { 0x55, 0x08, "Maximum Number Of Supplemental Decryption Keys Exceeded" }, 2100 { 0x55, 0x09, "Medium Auxiliary Memory Not Accessible" }, 2101 { 0x55, 0x0A, "Data Currently Unavailable" }, 2102 { 0x55, 0x0B, "Insufficient Power For Operation" }, 2103 { 0x57, 0x00, "Unable To Recover Table-Of-Contents" }, 2104 { 0x58, 0x00, "Generation Does Not Exist" }, 2105 { 0x59, 0x00, "Updated Block Read" }, 2106 { 0x5A, 0x00, "Operator Request or State Change Input" }, 2107 { 0x5A, 0x01, "Operator Medium Removal Requested" }, 2108 { 0x5A, 0x02, "Operator Selected Write Protect" }, 2109 { 0x5A, 0x03, "Operator Selected Write Permit" }, 2110 { 0x5B, 0x00, "Log Exception" }, 2111 { 0x5B, 0x01, "Threshold Condition Met" }, 2112 { 0x5B, 0x02, "Log Counter At Maximum" }, 2113 { 0x5B, 0x03, "Log List Codes Exhausted" }, 2114 { 0x5C, 0x00, "RPL Status Change" }, 2115 { 0x5C, 0x01, "Spindles Synchronized" }, 2116 { 0x5C, 0x02, "Spindles Not Synchronized" }, 2117 { 0x5D, 0x00, "Failure Prediction Threshold Exceeded" }, 2118 { 0x5D, 0x01, "Media Failure Prediction Threshold Exceeded" }, 2119 { 0x5D, 0x02, "Logical Unit Failure Prediction Threshold Exceeded" }, 2120 { 0x5D, 0x03, "Spare Area Exhaustion Prediction Threshold Exceeded" }, 2121 { 0x5D, 0x10, "Hardware Impending Failure General Hard Drive Failure" }, 2122 { 0x5D, 0x11, "Hardware Impending Failure Drive Error Rate Too High" }, 2123 { 0x5D, 0x12, "Hardware Impending Failure Data Error Rate Too High" }, 2124 { 0x5D, 0x13, "Hardware Impending Failure Seek Error Rate Too High" }, 2125 { 0x5D, 0x14, "Hardware Impending Failure Too Many Block Reassigns" }, 2126 { 0x5D, 0x15, "Hardware Impending Failure Access Times Too High" }, 2127 { 0x5D, 0x16, "Hardware Impending Failure Start Unit Times Too High" }, 2128 { 0x5D, 0x17, "Hardware Impending Failure Channel Parametrics" }, 2129 { 0x5D, 0x18, "Hardware Impending Failure Controller Detected" }, 2130 { 0x5D, 0x19, "Hardware Impending Failure Throughput Performance" }, 2131 { 0x5D, 0x1A, "Hardware Impending Failure Seek Time Performance" }, 2132 { 0x5D, 0x1B, "Hardware Impending Failure Spin-Up Retry Count" }, 2133 { 0x5D, 0x1C, "Hardware Impending Failure Drive Calibration Retry Count" }, 2134 { 0x5D, 0x20, "Controller Impending Failure General Hard Drive Failure" }, 2135 { 0x5D, 0x21, "Controller Impending Failure Drive Error Rate Too High" }, 2136 { 0x5D, 0x22, "Controller Impending Failure Data Error Rate Too High" }, 2137 { 0x5D, 0x23, "Controller Impending Failure Seek Error Rate Too High" }, 2138 { 0x5D, 0x24, "Controller Impending Failure Too Many Block Reassigns" }, 2139 { 0x5D, 0x25, "Controller Impending Failure Access Times Too High" }, 2140 { 0x5D, 0x26, "Controller Impending Failure Start Unit Times Too High" }, 2141 { 0x5D, 0x27, "Controller Impending Failure Channel Parametrics" }, 2142 { 0x5D, 0x28, "Controller Impending Failure Controller Detected" }, 2143 { 0x5D, 0x29, "Controller Impending Failure Throughput Performance" }, 2144 { 0x5D, 0x2A, "Controller Impending Failure Seek Time Performance" }, 2145 { 0x5D, 0x2B, "Controller Impending Failure Spin-Up Retry Count" }, 2146 { 0x5D, 0x2C, "Controller Impending Failure Drive Calibration Retry Count" }, 2147 { 0x5D, 0x30, "Data Channel Impending Failure General Hard Drive Failure" }, 2148 { 0x5D, 0x31, "Data Channel Impending Failure Drive Error Rate Too High" }, 2149 { 0x5D, 0x32, "Data Channel Impending Failure Data Error Rate Too High" }, 2150 { 0x5D, 0x33, "Data Channel Impending Failure Seek Error Rate Too High" }, 2151 { 0x5D, 0x34, "Data Channel Impending Failure Too Many Block Reassigns" }, 2152 { 0x5D, 0x35, "Data Channel Impending Failure Access Times Too High" }, 2153 { 0x5D, 0x36, "Data Channel Impending Failure Start Unit Times Too High" }, 2154 { 0x5D, 0x37, "Data Channel Impending Failure Channel Parametrics" }, 2155 { 0x5D, 0x38, "Data Channel Impending Failure Controller Detected" }, 2156 { 0x5D, 0x39, "Data Channel Impending Failure Throughput Performance" }, 2157 { 0x5D, 0x3A, "Data Channel Impending Failure Seek Time Performance" }, 2158 { 0x5D, 0x3B, "Data Channel Impending Failure Spin-Up Retry Count" }, 2159 { 0x5D, 0x3C, "Data Channel Impending Failure Drive Calibration Retry Count" }, 2160 { 0x5D, 0x40, "Servo Impending Failure General Hard Drive Failure" }, 2161 { 0x5D, 0x41, "Servo Impending Failure Drive Error Rate Too High" }, 2162 { 0x5D, 0x42, "Servo Impending Failure Data Error Rate Too High" }, 2163 { 0x5D, 0x43, "Servo Impending Failure Seek Error Rate Too High" }, 2164 { 0x5D, 0x44, "Servo Impending Failure Too Many Block Reassigns" }, 2165 { 0x5D, 0x45, "Servo Impending Failure Access Times Too High" }, 2166 { 0x5D, 0x46, "Servo Impending Failure Start Unit Times Too High" }, 2167 { 0x5D, 0x47, "Servo Impending Failure Channel Parametrics" }, 2168 { 0x5D, 0x48, "Servo Impending Failure Controller Detected" }, 2169 { 0x5D, 0x49, "Servo Impending Failure Throughput Performance" }, 2170 { 0x5D, 0x4A, "Servo Impending Failure Seek Time Performance" }, 2171 { 0x5D, 0x4B, "Servo Impending Failure Spin-Up Retry Count" }, 2172 { 0x5D, 0x4C, "Servo Impending Failure Drive Calibration Retry Count" }, 2173 { 0x5D, 0x50, "Spindle Impending Failure General Hard Drive Failure" }, 2174 { 0x5D, 0x51, "Spindle Impending Failure Drive Error Rate Too High" }, 2175 { 0x5D, 0x52, "Spindle Impending Failure Data Error Rate Too High" }, 2176 { 0x5D, 0x53, "Spindle Impending Failure Seek Error Rate Too High" }, 2177 { 0x5D, 0x54, "Spindle Impending Failure Too Many Block Reassigns" }, 2178 { 0x5D, 0x55, "Spindle Impending Failure Access Times Too High" }, 2179 { 0x5D, 0x56, "Spindle Impending Failure Start Unit Times Too High" }, 2180 { 0x5D, 0x57, "Spindle Impending Failure Channel Parametrics" }, 2181 { 0x5D, 0x58, "Spindle Impending Failure Controller Detected" }, 2182 { 0x5D, 0x59, "Spindle Impending Failure Throughput Performance" }, 2183 { 0x5D, 0x5A, "Spindle Impending Failure Seek Time Performance" }, 2184 { 0x5D, 0x5B, "Spindle Impending Failure Spin-Up Retry Count" }, 2185 { 0x5D, 0x5C, "Spindle Impending Failure Drive Calibration Retry Count" }, 2186 { 0x5D, 0x60, "Firmware Impending Failure General Hard Drive Failure" }, 2187 { 0x5D, 0x61, "Firmware Impending Failure Drive Error Rate Too High" }, 2188 { 0x5D, 0x62, "Firmware Impending Failure Data Error Rate Too High" }, 2189 { 0x5D, 0x63, "Firmware Impending Failure Seek Error Rate Too High" }, 2190 { 0x5D, 0x64, "Firmware Impending Failure Too Many Block Reassigns" }, 2191 { 0x5D, 0x65, "Firmware Impending Failure Access Times Too High" }, 2192 { 0x5D, 0x66, "Firmware Impending Failure Start Unit Times Too High" }, 2193 { 0x5D, 0x67, "Firmware Impending Failure Channel Parametrics" }, 2194 { 0x5D, 0x68, "Firmware Impending Failure Controller Detected" }, 2195 { 0x5D, 0x69, "Firmware Impending Failure Throughput Performance" }, 2196 { 0x5D, 0x6A, "Firmware Impending Failure Seek Time Performance" }, 2197 { 0x5D, 0x6B, "Firmware Impending Failure Spin-Up Retry Count" }, 2198 { 0x5D, 0x6C, "Firmware Impending Failure Drive Calibration Retry Count" }, 2199 { 0x5D, 0xFF, "Failure Prediction Threshold Exceeded (false)" }, 2200 { 0x5E, 0x00, "Low Power Condition On" }, 2201 { 0x5E, 0x01, "Idle Condition Activated By Timer" }, 2202 { 0x5E, 0x02, "Standby Condition Activated By Timer" }, 2203 { 0x5E, 0x03, "Idle Condition Activated By Command" }, 2204 { 0x5E, 0x04, "Standby Condition Activated By Command" }, 2205 { 0x5E, 0x05, "IDLE_B Condition Activated By Timer" }, 2206 { 0x5E, 0x06, "IDLE_B Condition Activated By Command" }, 2207 { 0x5E, 0x07, "IDLE_C Condition Activated By Timer" }, 2208 { 0x5E, 0x08, "IDLE_C Condition Activated By Command" }, 2209 { 0x5E, 0x09, "STANDBY_Y Condition Activated By Timer" }, 2210 { 0x5E, 0x0A, "STANDBY_Y Condition Activated By Command" }, 2211 { 0x5E, 0x41, "Power State Change To Active" }, 2212 { 0x5E, 0x42, "Power State Change To Idle" }, 2213 { 0x5E, 0x43, "Power State Change To Standby" }, 2214 { 0x5E, 0x45, "Power State Change To Sleep" }, 2215 { 0x5E, 0x47, "Power State Change To Device Control" }, 2216 { 0x60, 0x00, "Lamp Failure" }, 2217 { 0x61, 0x00, "Video Acquisition Error" }, 2218 { 0x61, 0x01, "Unable To Acquire Video" }, 2219 { 0x61, 0x02, "Out Of Focus" }, 2220 { 0x62, 0x00, "Scan Head Positioning Error" }, 2221 { 0x63, 0x00, "End Of User Area Encountered On This Track" }, 2222 { 0x63, 0x01, "Packet Does Not Fit In Available Space" }, 2223 { 0x64, 0x00, "Illegal Mode For This Track" }, 2224 { 0x64, 0x01, "Invalid Packet Size" }, 2225 { 0x65, 0x00, "Voltage Fault" }, 2226 { 0x66, 0x00, "Automatic Document Feeder Cover Up" }, 2227 { 0x66, 0x01, "Automatic Document Feeder Lift Up" }, 2228 { 0x66, 0x02, "Document Jam In Automatic Document Feeder" }, 2229 { 0x66, 0x03, "Document Miss Feed Automatic In Document Feeder" }, 2230 { 0x67, 0x00, "Configuration Failure" }, 2231 { 0x67, 0x01, "Configuration Of Incapable Logical Units Failed" }, 2232 { 0x67, 0x02, "Add Logical Unit Failed" }, 2233 { 0x67, 0x03, "Modification Of Logical Unit Failed" }, 2234 { 0x67, 0x04, "Exchange Of Logical Unit Failed" }, 2235 { 0x67, 0x05, "Remove Of Logical Unit Failed" }, 2236 { 0x67, 0x06, "Attachment Of Logical Unit Failed" }, 2237 { 0x67, 0x07, "Creation Of Logical Unit Failed" }, 2238 { 0x67, 0x08, "Assign Failure Occurred" }, 2239 { 0x67, 0x09, "Multiply Assigned Logical Unit" }, 2240 { 0x67, 0x0A, "Set Target Port Groups Command Failed" }, 2241 { 0x67, 0x0B, "ATA Device Feature Not Enabled" }, 2242 { 0x68, 0x00, "Logical Unit Not Configured" }, 2243 { 0x69, 0x00, "Data Loss On Logical Unit" }, 2244 { 0x69, 0x01, "Multiple Logical Unit Failures" }, 2245 { 0x69, 0x02, "Parity/Data Mismatch" }, 2246 { 0x6A, 0x00, "Informational, Refer To Log" }, 2247 { 0x6B, 0x00, "State Change Has Occurred" }, 2248 { 0x6B, 0x01, "Redundancy Level Got Better" }, 2249 { 0x6B, 0x02, "Redundancy Level Got Worse" }, 2250 { 0x6C, 0x00, "Rebuild Failure Occurred" }, 2251 { 0x6D, 0x00, "Recalculate Failure Occurred" }, 2252 { 0x6E, 0x00, "Command To Logical Unit Failed" }, 2253 { 0x6F, 0x00, "Copy Protection Key Exchange Failure - Authentication Failure" }, 2254 { 0x6F, 0x01, "Copy Protection Key Exchange Failure - Key Not Present" }, 2255 { 0x6F, 0x02, "Copy Protection Key Exchange Failure - Key Not Established" }, 2256 { 0x6F, 0x03, "Read Of Scrambled Sector Without Authentication" }, 2257 { 0x6F, 0x04, "Media Region Code Is Mismatched To Logical Unit Region" }, 2258 { 0x6F, 0x05, "Drive Region Must Be Permanent/Region Reset Count Error" }, 2259 /* 2260 * ASC 0x70 has an ASCQ range from 0x00 to 0xFF. 2261 * 0x70 0xNN DECOMPRESSION EXCEPTION SHORT ALGORITHM ID Of NN 2262 */ 2263 { 0x71, 0x00, "Decompression Exception Long Algorithm ID" }, 2264 { 0x72, 0x00, "Session Fixation Error" }, 2265 { 0x72, 0x01, "Session Fixation Error Writing Lead-In" }, 2266 { 0x72, 0x02, "Session Fixation Error Writing Lead-Out" }, 2267 { 0x72, 0x03, "Session Fixation Error - Incomplete Track In Session" }, 2268 { 0x72, 0x04, "Empty Or Partially Written Reserved Track" }, 2269 { 0x72, 0x05, "No More Track Reservations Allowed" }, 2270 { 0x72, 0x06, "RMZ Extension Is Not Allowed" }, 2271 { 0x72, 0x07, "No More Test Zone Extensions Are Allowed" }, 2272 { 0x73, 0x00, "CD Control Error" }, 2273 { 0x73, 0x01, "Power Calibration Area Almost Full" }, 2274 { 0x73, 0x02, "Power Calibration Area Is Full" }, 2275 { 0x73, 0x03, "Power Calibration Area Error" }, 2276 { 0x73, 0x04, "Program Memory Area Update Failure" }, 2277 { 0x73, 0x05, "Program Memory Area Is Full" }, 2278 { 0x73, 0x06, "RMA/PMA Is Almost Full" }, 2279 { 0x73, 0x10, "Current Power Calibration Area Almost Full" }, 2280 { 0x73, 0x11, "Current Power Calibration Area Is Full" }, 2281 { 0x73, 0x17, "RDZ Is Full" }, 2282 { 0x74, 0x00, "Security Error" }, 2283 { 0x74, 0x01, "Unable To Decrypt Data" }, 2284 { 0x74, 0x02, "Unencrypted Data Encountered While Decrypting" }, 2285 { 0x74, 0x03, "Incorrect Data Encryption Key" }, 2286 { 0x74, 0x04, "Cryptographic Integrity Validation Failed" }, 2287 { 0x74, 0x05, "Error Decrypting Data" }, 2288 { 0x74, 0x06, "Unknown Signature Verification Key" }, 2289 { 0x74, 0x07, "Encryption Parameters Not Useable" }, 2290 { 0x74, 0x08, "Digital Signature Validation Failure" }, 2291 { 0x74, 0x09, "Encryption Mode Mismatch On Read" }, 2292 { 0x74, 0x0A, "Encrypted Block Not Raw Read Enabled" }, 2293 { 0x74, 0x0B, "Incorrect Encryption Parameters" }, 2294 { 0x74, 0x0C, "Unable To Decrypt Parameter List" }, 2295 { 0x74, 0x0D, "Encryption Algorithm Disabled" }, 2296 { 0x74, 0x10, "SA Creation Parameter Value Invalid" }, 2297 { 0x74, 0x11, "SA Creation Parameter Value Rejected" }, 2298 { 0x74, 0x12, "Invalid SA Usage" }, 2299 { 0x74, 0x21, "Data Encryption Configuration Prevented" }, 2300 { 0x74, 0x30, "SA Creation Parameter Not Supported" }, 2301 { 0x74, 0x40, "Authentication Failed" }, 2302 { 0x74, 0x61, "External Data Encryption Key Manager Access Error" }, 2303 { 0x74, 0x62, "External Data Encryption Key Manager Error" }, 2304 { 0x74, 0x63, "External Data Encryption Key Not Found" }, 2305 { 0x74, 0x64, "External Data Encryption Request Not Authorized" }, 2306 { 0x74, 0x6E, "External Data Encryption Control Timeout" }, 2307 { 0x74, 0x6F, "External Data Encryption Control Error" }, 2308 { 0x74, 0x71, "Logical Unit Access Not Authorized" }, 2309 { 0x74, 0x79, "Security Conflict In Translated Device" }, 2310 { 0x00, 0x00, NULL } 2311 }; 2312 2313 static __inline void 2314 asc2ascii(u_int8_t asc, u_int8_t ascq, char *result, size_t len) 2315 { 2316 int i; 2317 2318 /* Check for a dynamically built description. */ 2319 switch (asc) { 2320 case 0x40: 2321 if (ascq >= 0x80) { 2322 snprintf(result, len, 2323 "Diagnostic Failure on Component 0x%02x", ascq); 2324 return; 2325 } 2326 break; 2327 case 0x4d: 2328 snprintf(result, len, 2329 "Tagged Overlapped Commands (0x%02x = TASK TAG)", ascq); 2330 return; 2331 case 0x70: 2332 snprintf(result, len, 2333 "Decompression Exception Short Algorithm ID OF 0x%02x", 2334 ascq); 2335 return; 2336 default: 2337 break; 2338 } 2339 2340 /* Check for a fixed description. */ 2341 for (i = 0; adesc[i].description != NULL; i++) { 2342 if (adesc[i].asc == asc && adesc[i].ascq == ascq) { 2343 strlcpy(result, adesc[i].description, len); 2344 return; 2345 } 2346 } 2347 2348 /* Just print out the ASC and ASCQ values as a description. */ 2349 snprintf(result, len, "ASC 0x%02x ASCQ 0x%02x", asc, ascq); 2350 } 2351 #endif /* SCSITERSE */ 2352 2353 void 2354 scsi_print_sense(struct scsi_xfer *xs) 2355 { 2356 struct scsi_sense_data *sense = &xs->sense; 2357 u_int8_t serr = sense->error_code & 2358 SSD_ERRCODE; 2359 int32_t info; 2360 char *sbs; 2361 2362 sc_print_addr(xs->sc_link); 2363 2364 /* XXX For error 0x71, current opcode is not the relevant one. */ 2365 printf("%sCheck Condition (error %#x) on opcode 0x%x\n", 2366 (serr == SSD_ERRCODE_DEFERRED) ? "DEFERRED " : "", serr, 2367 xs->cmd->opcode); 2368 2369 if (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED) { 2370 if ((sense->error_code & SSD_ERRCODE_VALID) != 0) { 2371 struct scsi_sense_data_unextended *usense = 2372 (struct scsi_sense_data_unextended *)sense; 2373 printf(" AT BLOCK #: %d (decimal)", 2374 _3btol(usense->block)); 2375 } 2376 return; 2377 } 2378 2379 printf(" SENSE KEY: %s\n", scsi_decode_sense(sense, 2380 DECODE_SENSE_KEY)); 2381 2382 if (sense->flags & (SSD_FILEMARK | SSD_EOM | SSD_ILI)) { 2383 char pad = ' '; 2384 2385 printf(" "); 2386 if (sense->flags & SSD_FILEMARK) { 2387 printf("%c Filemark Detected", pad); 2388 pad = ','; 2389 } 2390 if (sense->flags & SSD_EOM) { 2391 printf("%c EOM Detected", pad); 2392 pad = ','; 2393 } 2394 if (sense->flags & SSD_ILI) 2395 printf("%c Incorrect Length Indicator Set", pad); 2396 printf("\n"); 2397 } 2398 2399 /* 2400 * It is inconvenient to use device type to figure out how to 2401 * format the info fields. So print them as 32 bit integers. 2402 */ 2403 info = _4btol(&sense->info[0]); 2404 if (info) 2405 printf(" INFO: 0x%x (VALID flag %s)\n", info, 2406 sense->error_code & SSD_ERRCODE_VALID ? "on" : "off"); 2407 2408 if (sense->extra_len < 4) 2409 return; 2410 2411 info = _4btol(&sense->cmd_spec_info[0]); 2412 if (info) 2413 printf(" COMMAND INFO: 0x%x\n", info); 2414 sbs = scsi_decode_sense(sense, DECODE_ASC_ASCQ); 2415 if (strlen(sbs) > 0) 2416 printf(" ASC/ASCQ: %s\n", sbs); 2417 if (sense->fru != 0) 2418 printf(" FRU CODE: 0x%x\n", sense->fru); 2419 sbs = scsi_decode_sense(sense, DECODE_SKSV); 2420 if (strlen(sbs) > 0) 2421 printf(" SKSV: %s\n", sbs); 2422 } 2423 2424 char * 2425 scsi_decode_sense(struct scsi_sense_data *sense, int flag) 2426 { 2427 static char rqsbuf[132]; 2428 u_int16_t count; 2429 u_int8_t skey, spec_1; 2430 int len; 2431 2432 bzero(rqsbuf, sizeof(rqsbuf)); 2433 2434 skey = sense->flags & SSD_KEY; 2435 spec_1 = sense->sense_key_spec_1; 2436 count = _2btol(&sense->sense_key_spec_2); 2437 2438 switch (flag) { 2439 case DECODE_SENSE_KEY: 2440 strlcpy(rqsbuf, sense_keys[skey], sizeof(rqsbuf)); 2441 break; 2442 case DECODE_ASC_ASCQ: 2443 asc2ascii(sense->add_sense_code, sense->add_sense_code_qual, 2444 rqsbuf, sizeof(rqsbuf)); 2445 break; 2446 case DECODE_SKSV: 2447 if (sense->extra_len < 9 || ((spec_1 & SSD_SCS_VALID) == 0)) 2448 break; 2449 switch (skey) { 2450 case SKEY_ILLEGAL_REQUEST: 2451 len = snprintf(rqsbuf, sizeof rqsbuf, 2452 "Error in %s, Offset %d", 2453 (spec_1 & SSD_SCS_CDB_ERROR) ? "CDB" : "Parameters", 2454 count); 2455 if ((len != -1 && len < sizeof rqsbuf) && 2456 (spec_1 & SSD_SCS_VALID_BIT_INDEX)) 2457 snprintf(rqsbuf+len, sizeof rqsbuf - len, 2458 ", bit %d", spec_1 & SSD_SCS_BIT_INDEX); 2459 break; 2460 case SKEY_RECOVERED_ERROR: 2461 case SKEY_MEDIUM_ERROR: 2462 case SKEY_HARDWARE_ERROR: 2463 snprintf(rqsbuf, sizeof rqsbuf, 2464 "Actual Retry Count: %d", count); 2465 break; 2466 case SKEY_NOT_READY: 2467 snprintf(rqsbuf, sizeof rqsbuf, 2468 "Progress Indicator: %d", count); 2469 break; 2470 default: 2471 break; 2472 } 2473 break; 2474 default: 2475 break; 2476 } 2477 2478 return (rqsbuf); 2479 } 2480 2481 #ifdef SCSIDEBUG 2482 /* 2483 * Given a scsi_xfer, dump the request, in all its glory 2484 */ 2485 void 2486 scsi_xs_show(struct scsi_xfer *xs) 2487 { 2488 u_char *b = (u_char *)xs->cmd; 2489 int i = 0; 2490 2491 sc_print_addr(xs->sc_link); 2492 printf("xs (%p): ", xs); 2493 2494 printf("flg(0x%x)", xs->flags); 2495 printf("sc_link(%p)", xs->sc_link); 2496 printf("retr(0x%x)", xs->retries); 2497 printf("timo(0x%x)", xs->timeout); 2498 printf("data(%p)", xs->data); 2499 printf("res(0x%x)", xs->resid); 2500 printf("err(0x%x)", xs->error); 2501 printf("bp(%p)\n", xs->bp); 2502 2503 sc_print_addr(xs->sc_link); 2504 printf("cmd (%p): ", xs->cmd); 2505 2506 if ((xs->flags & SCSI_RESET) == 0) { 2507 while (i < xs->cmdlen) { 2508 if (i) 2509 printf(","); 2510 printf("%x", b[i++]); 2511 } 2512 printf("-[%d bytes]\n", xs->datalen); 2513 } else 2514 printf("-RESET-\n"); 2515 } 2516 2517 void 2518 scsi_show_mem(u_char *address, int num) 2519 { 2520 int x; 2521 2522 printf("------------------------------"); 2523 for (x = 0; x < num; x++) { 2524 if ((x % 16) == 0) 2525 printf("\n%03d: ", x); 2526 printf("%02x ", *address++); 2527 } 2528 printf("\n------------------------------\n"); 2529 } 2530 #endif /* SCSIDEBUG */ 2531 2532 void 2533 scsi_cmd_rw_decode(struct scsi_generic *cmd, u_int64_t *blkno, 2534 u_int32_t *nblks) 2535 { 2536 switch (cmd->opcode) { 2537 case READ_COMMAND: 2538 case WRITE_COMMAND: { 2539 struct scsi_rw *rw = (struct scsi_rw *)cmd; 2540 *blkno = _3btol(rw->addr) & (SRW_TOPADDR << 16 | 0xffff); 2541 *nblks = rw->length ? rw->length : 0x100; 2542 break; 2543 } 2544 case READ_BIG: 2545 case WRITE_BIG: { 2546 struct scsi_rw_big *rwb = (struct scsi_rw_big *)cmd; 2547 *blkno = _4btol(rwb->addr); 2548 *nblks = _2btol(rwb->length); 2549 break; 2550 } 2551 case READ_12: 2552 case WRITE_12: { 2553 struct scsi_rw_12 *rw12 = (struct scsi_rw_12 *)cmd; 2554 *blkno = _4btol(rw12->addr); 2555 *nblks = _4btol(rw12->length); 2556 break; 2557 } 2558 case READ_16: 2559 case WRITE_16: { 2560 struct scsi_rw_16 *rw16 = (struct scsi_rw_16 *)cmd; 2561 *blkno = _8btol(rw16->addr); 2562 *nblks = _4btol(rw16->length); 2563 break; 2564 } 2565 default: 2566 panic("scsi_cmd_rw_decode: bad opcode 0x%02x", cmd->opcode); 2567 } 2568 } 2569