1 /*- 2 * Copyright (c) 2003-2009 Silicon Graphics International Corp. 3 * Copyright (c) 2011 Spectra Logic Corporation 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer, 11 * without modification. 12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 13 * substantially similar to the "NO WARRANTY" disclaimer below 14 * ("Disclaimer") and any redistribution must be conditioned upon 15 * including a substantially similar Disclaimer requirement for further 16 * binary redistribution. 17 * 18 * NO WARRANTY 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGES. 30 * 31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_error.c#2 $ 32 */ 33 /* 34 * CAM Target Layer error reporting routines. 35 * 36 * Author: Ken Merry <ken@FreeBSD.org> 37 */ 38 39 #include <sys/cdefs.h> 40 __FBSDID("$FreeBSD$"); 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/kernel.h> 45 #include <sys/types.h> 46 #include <sys/malloc.h> 47 #include <sys/lock.h> 48 #include <sys/mutex.h> 49 #include <sys/condvar.h> 50 #include <sys/stddef.h> 51 #include <sys/ctype.h> 52 #include <machine/stdarg.h> 53 54 #include <cam/scsi/scsi_all.h> 55 #include <cam/scsi/scsi_da.h> 56 #include <cam/ctl/ctl_io.h> 57 #include <cam/ctl/ctl.h> 58 #include <cam/ctl/ctl_frontend.h> 59 #include <cam/ctl/ctl_frontend_internal.h> 60 #include <cam/ctl/ctl_backend.h> 61 #include <cam/ctl/ctl_ioctl.h> 62 #include <cam/ctl/ctl_error.h> 63 #include <cam/ctl/ctl_ha.h> 64 #include <cam/ctl/ctl_private.h> 65 66 void 67 ctl_set_sense_data_va(struct scsi_sense_data *sense_data, void *lunptr, 68 scsi_sense_data_type sense_format, int current_error, 69 int sense_key, int asc, int ascq, va_list ap) 70 { 71 struct ctl_lun *lun; 72 73 lun = (struct ctl_lun *)lunptr; 74 75 /* 76 * Determine whether to return fixed or descriptor format sense 77 * data. 78 */ 79 if (sense_format == SSD_TYPE_NONE) { 80 /* 81 * If the format isn't specified, we only return descriptor 82 * sense if the LUN exists and descriptor sense is turned 83 * on for that LUN. 84 */ 85 if ((lun != NULL) 86 && (lun->flags & CTL_LUN_SENSE_DESC)) 87 sense_format = SSD_TYPE_DESC; 88 else 89 sense_format = SSD_TYPE_FIXED; 90 } 91 92 scsi_set_sense_data_va(sense_data, sense_format, current_error, 93 sense_key, asc, ascq, ap); 94 } 95 96 void 97 ctl_set_sense_data(struct scsi_sense_data *sense_data, void *lunptr, 98 scsi_sense_data_type sense_format, int current_error, 99 int sense_key, int asc, int ascq, ...) 100 { 101 va_list ap; 102 103 va_start(ap, ascq); 104 ctl_set_sense_data_va(sense_data, lunptr, sense_format, current_error, 105 sense_key, asc, ascq, ap); 106 va_end(ap); 107 } 108 109 void 110 ctl_set_sense(struct ctl_scsiio *ctsio, int current_error, int sense_key, 111 int asc, int ascq, ...) 112 { 113 va_list ap; 114 struct ctl_lun *lun; 115 116 /* 117 * The LUN can't go away until all of the commands have been 118 * completed. Therefore we can safely access the LUN structure and 119 * flags without the lock. 120 */ 121 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 122 123 va_start(ap, ascq); 124 ctl_set_sense_data_va(&ctsio->sense_data, 125 lun, 126 SSD_TYPE_NONE, 127 current_error, 128 sense_key, 129 asc, 130 ascq, 131 ap); 132 va_end(ap); 133 134 ctsio->scsi_status = SCSI_STATUS_CHECK_COND; 135 ctsio->sense_len = SSD_FULL_SIZE; 136 ctsio->io_hdr.status = CTL_SCSI_ERROR | CTL_AUTOSENSE; 137 } 138 139 /* 140 * Transform fixed sense data into descriptor sense data. 141 * 142 * For simplicity's sake, we assume that both sense structures are 143 * SSD_FULL_SIZE. Otherwise, the logic gets more complicated. 144 */ 145 void 146 ctl_sense_to_desc(struct scsi_sense_data_fixed *sense_src, 147 struct scsi_sense_data_desc *sense_dest) 148 { 149 struct scsi_sense_stream stream_sense; 150 int current_error; 151 uint8_t stream_bits; 152 153 bzero(sense_dest, sizeof(*sense_dest)); 154 155 if ((sense_src->error_code & SSD_ERRCODE) == SSD_DEFERRED_ERROR) 156 current_error = 0; 157 else 158 current_error = 1; 159 160 bzero(&stream_sense, sizeof(stream_sense)); 161 162 /* 163 * Check to see whether any of the tape-specific bits are set. If 164 * so, we'll need a stream sense descriptor. 165 */ 166 if (sense_src->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) 167 stream_bits = sense_src->flags & ~SSD_KEY; 168 else 169 stream_bits = 0; 170 171 /* 172 * Utilize our sense setting routine to do the transform. If a 173 * value is set in the fixed sense data, set it in the descriptor 174 * data. Otherwise, skip it. 175 */ 176 ctl_set_sense_data((struct scsi_sense_data *)sense_dest, 177 /*lun*/ NULL, 178 /*sense_format*/ SSD_TYPE_DESC, 179 current_error, 180 /*sense_key*/ sense_src->flags & SSD_KEY, 181 /*asc*/ sense_src->add_sense_code, 182 /*ascq*/ sense_src->add_sense_code_qual, 183 184 /* Information Bytes */ 185 (scsi_4btoul(sense_src->info) != 0) ? 186 SSD_ELEM_INFO : SSD_ELEM_SKIP, 187 sizeof(sense_src->info), 188 sense_src->info, 189 190 /* Command specific bytes */ 191 (scsi_4btoul(sense_src->cmd_spec_info) != 0) ? 192 SSD_ELEM_COMMAND : SSD_ELEM_SKIP, 193 sizeof(sense_src->cmd_spec_info), 194 sense_src->cmd_spec_info, 195 196 /* FRU */ 197 (sense_src->fru != 0) ? 198 SSD_ELEM_FRU : SSD_ELEM_SKIP, 199 sizeof(sense_src->fru), 200 &sense_src->fru, 201 202 /* Sense Key Specific */ 203 (sense_src->sense_key_spec[0] & SSD_SCS_VALID) ? 204 SSD_ELEM_SKS : SSD_ELEM_SKIP, 205 sizeof(sense_src->sense_key_spec), 206 sense_src->sense_key_spec, 207 208 /* Tape bits */ 209 (stream_bits != 0) ? 210 SSD_ELEM_STREAM : SSD_ELEM_SKIP, 211 sizeof(stream_bits), 212 &stream_bits, 213 214 SSD_ELEM_NONE); 215 } 216 217 /* 218 * Transform descriptor format sense data into fixed sense data. 219 * 220 * Some data may be lost in translation, because there are descriptors 221 * thant can't be represented as fixed sense data. 222 * 223 * For simplicity's sake, we assume that both sense structures are 224 * SSD_FULL_SIZE. Otherwise, the logic gets more complicated. 225 */ 226 void 227 ctl_sense_to_fixed(struct scsi_sense_data_desc *sense_src, 228 struct scsi_sense_data_fixed *sense_dest) 229 { 230 int current_error; 231 uint8_t *info_ptr = NULL, *cmd_ptr = NULL, *fru_ptr = NULL; 232 uint8_t *sks_ptr = NULL, *stream_ptr = NULL; 233 int info_size = 0, cmd_size = 0, fru_size = 0; 234 int sks_size = 0, stream_size = 0; 235 int pos; 236 237 if ((sense_src->error_code & SSD_ERRCODE) == SSD_DESC_CURRENT_ERROR) 238 current_error = 1; 239 else 240 current_error = 0; 241 242 for (pos = 0; pos < (int)(sense_src->extra_len - 1);) { 243 struct scsi_sense_desc_header *header; 244 245 header = (struct scsi_sense_desc_header *) 246 &sense_src->sense_desc[pos]; 247 248 /* 249 * See if this record goes past the end of the sense data. 250 * It shouldn't, but check just in case. 251 */ 252 if ((pos + header->length + sizeof(*header)) > 253 sense_src->extra_len) 254 break; 255 256 switch (sense_src->sense_desc[pos]) { 257 case SSD_DESC_INFO: { 258 struct scsi_sense_info *info; 259 260 info = (struct scsi_sense_info *)header; 261 262 info_ptr = info->info; 263 info_size = sizeof(info->info); 264 265 pos += info->length + 266 sizeof(struct scsi_sense_desc_header); 267 break; 268 } 269 case SSD_DESC_COMMAND: { 270 struct scsi_sense_command *cmd; 271 272 cmd = (struct scsi_sense_command *)header; 273 cmd_ptr = cmd->command_info; 274 cmd_size = sizeof(cmd->command_info); 275 276 pos += cmd->length + 277 sizeof(struct scsi_sense_desc_header); 278 break; 279 } 280 case SSD_DESC_FRU: { 281 struct scsi_sense_fru *fru; 282 283 fru = (struct scsi_sense_fru *)header; 284 fru_ptr = &fru->fru; 285 fru_size = sizeof(fru->fru); 286 pos += fru->length + 287 sizeof(struct scsi_sense_desc_header); 288 break; 289 } 290 case SSD_DESC_SKS: { 291 struct scsi_sense_sks *sks; 292 293 sks = (struct scsi_sense_sks *)header; 294 sks_ptr = sks->sense_key_spec; 295 sks_size = sizeof(sks->sense_key_spec); 296 297 pos = sks->length + 298 sizeof(struct scsi_sense_desc_header); 299 break; 300 } 301 case SSD_DESC_STREAM: { 302 struct scsi_sense_stream *stream_sense; 303 304 stream_sense = (struct scsi_sense_stream *)header; 305 stream_ptr = &stream_sense->byte3; 306 stream_size = sizeof(stream_sense->byte3); 307 pos = stream_sense->length + 308 sizeof(struct scsi_sense_desc_header); 309 break; 310 } 311 default: 312 /* 313 * We don't recognize this particular sense 314 * descriptor type, so just skip it. 315 */ 316 pos += sizeof(*header) + header->length; 317 break; 318 } 319 } 320 321 ctl_set_sense_data((struct scsi_sense_data *)sense_dest, 322 /*lun*/ NULL, 323 /*sense_format*/ SSD_TYPE_FIXED, 324 current_error, 325 /*sense_key*/ sense_src->sense_key & SSD_KEY, 326 /*asc*/ sense_src->add_sense_code, 327 /*ascq*/ sense_src->add_sense_code_qual, 328 329 /* Information Bytes */ 330 (info_ptr != NULL) ? SSD_ELEM_INFO : SSD_ELEM_SKIP, 331 info_size, 332 info_ptr, 333 334 /* Command specific bytes */ 335 (cmd_ptr != NULL) ? SSD_ELEM_COMMAND : SSD_ELEM_SKIP, 336 cmd_size, 337 cmd_ptr, 338 339 /* FRU */ 340 (fru_ptr != NULL) ? SSD_ELEM_FRU : SSD_ELEM_SKIP, 341 fru_size, 342 fru_ptr, 343 344 /* Sense Key Specific */ 345 (sks_ptr != NULL) ? SSD_ELEM_SKS : SSD_ELEM_SKIP, 346 sks_size, 347 sks_ptr, 348 349 /* Tape bits */ 350 (stream_ptr != NULL) ? SSD_ELEM_STREAM : SSD_ELEM_SKIP, 351 stream_size, 352 stream_ptr, 353 354 SSD_ELEM_NONE); 355 } 356 357 void 358 ctl_set_ua(struct ctl_scsiio *ctsio, int asc, int ascq) 359 { 360 ctl_set_sense(ctsio, 361 /*current_error*/ 1, 362 /*sense_key*/ SSD_KEY_UNIT_ATTENTION, 363 asc, 364 ascq, 365 SSD_ELEM_NONE); 366 } 367 368 ctl_ua_type 369 ctl_build_ua(ctl_ua_type ua_type, struct scsi_sense_data *sense, 370 scsi_sense_data_type sense_format) 371 { 372 ctl_ua_type ua_to_build; 373 int i, asc, ascq; 374 375 if (ua_type == CTL_UA_NONE) 376 return (ua_type); 377 378 ua_to_build = CTL_UA_NONE; 379 380 for (i = 0; i < (sizeof(ua_type) * 8); i++) { 381 if (ua_type & (1 << i)) { 382 ua_to_build = 1 << i; 383 break; 384 } 385 } 386 387 switch (ua_to_build) { 388 case CTL_UA_POWERON: 389 /* 29h/01h POWER ON OCCURRED */ 390 asc = 0x29; 391 ascq = 0x01; 392 break; 393 case CTL_UA_BUS_RESET: 394 /* 29h/02h SCSI BUS RESET OCCURRED */ 395 asc = 0x29; 396 ascq = 0x02; 397 break; 398 case CTL_UA_TARG_RESET: 399 /* 29h/03h BUS DEVICE RESET FUNCTION OCCURRED*/ 400 asc = 0x29; 401 ascq = 0x03; 402 break; 403 case CTL_UA_LUN_RESET: 404 /* 29h/00h POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */ 405 /* 406 * Since we don't have a specific ASC/ASCQ pair for a LUN 407 * reset, just return the generic reset code. 408 */ 409 asc = 0x29; 410 ascq = 0x00; 411 break; 412 case CTL_UA_LUN_CHANGE: 413 /* 3Fh/0Eh REPORTED LUNS DATA HAS CHANGED */ 414 asc = 0x3F; 415 ascq = 0x0E; 416 break; 417 case CTL_UA_MODE_CHANGE: 418 /* 2Ah/01h MODE PARAMETERS CHANGED */ 419 asc = 0x2A; 420 ascq = 0x01; 421 break; 422 case CTL_UA_LOG_CHANGE: 423 /* 2Ah/02h LOG PARAMETERS CHANGED */ 424 asc = 0x2A; 425 ascq = 0x02; 426 break; 427 case CTL_UA_LVD: 428 /* 29h/06h TRANSCEIVER MODE CHANGED TO LVD */ 429 asc = 0x29; 430 ascq = 0x06; 431 break; 432 case CTL_UA_SE: 433 /* 29h/05h TRANSCEIVER MODE CHANGED TO SINGLE-ENDED */ 434 asc = 0x29; 435 ascq = 0x05; 436 break; 437 case CTL_UA_RES_PREEMPT: 438 /* 2Ah/03h RESERVATIONS PREEMPTED */ 439 asc = 0x2A; 440 ascq = 0x03; 441 break; 442 case CTL_UA_RES_RELEASE: 443 /* 2Ah/04h RESERVATIONS RELEASED */ 444 asc = 0x2A; 445 ascq = 0x04; 446 break; 447 case CTL_UA_REG_PREEMPT: 448 /* 2Ah/05h REGISTRATIONS PREEMPTED */ 449 asc = 0x2A; 450 ascq = 0x05; 451 break; 452 case CTL_UA_ASYM_ACC_CHANGE: 453 /* 2Ah/06n ASYMMETRIC ACCESS STATE CHANGED */ 454 asc = 0x2A; 455 ascq = 0x06; 456 break; 457 default: 458 ua_to_build = CTL_UA_NONE; 459 return (ua_to_build); 460 break; /* NOTREACHED */ 461 } 462 463 ctl_set_sense_data(sense, 464 /*lun*/ NULL, 465 sense_format, 466 /*current_error*/ 1, 467 /*sense_key*/ SSD_KEY_UNIT_ATTENTION, 468 asc, 469 ascq, 470 SSD_ELEM_NONE); 471 472 return (ua_to_build); 473 } 474 475 void 476 ctl_set_overlapped_cmd(struct ctl_scsiio *ctsio) 477 { 478 /* OVERLAPPED COMMANDS ATTEMPTED */ 479 ctl_set_sense(ctsio, 480 /*current_error*/ 1, 481 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 482 /*asc*/ 0x4E, 483 /*ascq*/ 0x00, 484 SSD_ELEM_NONE); 485 } 486 487 void 488 ctl_set_overlapped_tag(struct ctl_scsiio *ctsio, uint8_t tag) 489 { 490 /* TAGGED OVERLAPPED COMMANDS (NN = QUEUE TAG) */ 491 ctl_set_sense(ctsio, 492 /*current_error*/ 1, 493 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 494 /*asc*/ 0x4D, 495 /*ascq*/ tag, 496 SSD_ELEM_NONE); 497 } 498 499 /* 500 * Tell the user that there was a problem with the command or data he sent. 501 */ 502 void 503 ctl_set_invalid_field(struct ctl_scsiio *ctsio, int sks_valid, int command, 504 int field, int bit_valid, int bit) 505 { 506 uint8_t sks[3]; 507 int asc; 508 509 if (command != 0) { 510 /* "Invalid field in CDB" */ 511 asc = 0x24; 512 } else { 513 /* "Invalid field in parameter list" */ 514 asc = 0x26; 515 } 516 517 if (sks_valid) { 518 sks[0] = SSD_SCS_VALID; 519 if (command) 520 sks[0] |= SSD_FIELDPTR_CMD; 521 scsi_ulto2b(field, &sks[1]); 522 523 if (bit_valid) 524 sks[0] |= SSD_BITPTR_VALID | bit; 525 } 526 527 ctl_set_sense(ctsio, 528 /*current_error*/ 1, 529 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 530 asc, 531 /*ascq*/ 0x00, 532 /*type*/ (sks_valid != 0) ? SSD_ELEM_SKS : SSD_ELEM_SKIP, 533 /*size*/ sizeof(sks), 534 /*data*/ sks, 535 SSD_ELEM_NONE); 536 } 537 538 void 539 ctl_set_invalid_opcode(struct ctl_scsiio *ctsio) 540 { 541 struct scsi_sense_data *sense; 542 uint8_t sks[3]; 543 544 sense = &ctsio->sense_data; 545 546 sks[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD; 547 scsi_ulto2b(0, &sks[1]); 548 549 /* "Invalid command operation code" */ 550 ctl_set_sense(ctsio, 551 /*current_error*/ 1, 552 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 553 /*asc*/ 0x20, 554 /*ascq*/ 0x00, 555 /*type*/ SSD_ELEM_SKS, 556 /*size*/ sizeof(sks), 557 /*data*/ sks, 558 SSD_ELEM_NONE); 559 } 560 561 void 562 ctl_set_param_len_error(struct ctl_scsiio *ctsio) 563 { 564 /* "Parameter list length error" */ 565 ctl_set_sense(ctsio, 566 /*current_error*/ 1, 567 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 568 /*asc*/ 0x1a, 569 /*ascq*/ 0x00, 570 SSD_ELEM_NONE); 571 } 572 573 void 574 ctl_set_already_locked(struct ctl_scsiio *ctsio) 575 { 576 /* Vendor unique "Somebody already is locked" */ 577 ctl_set_sense(ctsio, 578 /*current_error*/ 1, 579 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 580 /*asc*/ 0x81, 581 /*ascq*/ 0x00, 582 SSD_ELEM_NONE); 583 } 584 585 void 586 ctl_set_unsupported_lun(struct ctl_scsiio *ctsio) 587 { 588 /* "Logical unit not supported" */ 589 ctl_set_sense(ctsio, 590 /*current_error*/ 1, 591 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 592 /*asc*/ 0x25, 593 /*ascq*/ 0x00, 594 SSD_ELEM_NONE); 595 } 596 597 void 598 ctl_set_internal_failure(struct ctl_scsiio *ctsio, int sks_valid, 599 uint16_t retry_count) 600 { 601 uint8_t sks[3]; 602 603 if (sks_valid) { 604 sks[0] = SSD_SCS_VALID; 605 sks[1] = (retry_count >> 8) & 0xff; 606 sks[2] = retry_count & 0xff; 607 } 608 609 /* "Internal target failure" */ 610 ctl_set_sense(ctsio, 611 /*current_error*/ 1, 612 /*sense_key*/ SSD_KEY_HARDWARE_ERROR, 613 /*asc*/ 0x44, 614 /*ascq*/ 0x00, 615 /*type*/ (sks_valid != 0) ? SSD_ELEM_SKS : SSD_ELEM_SKIP, 616 /*size*/ sizeof(sks), 617 /*data*/ sks, 618 SSD_ELEM_NONE); 619 } 620 621 void 622 ctl_set_medium_error(struct ctl_scsiio *ctsio) 623 { 624 if ((ctsio->io_hdr.flags & CTL_FLAG_DATA_MASK) == CTL_FLAG_DATA_IN) { 625 /* "Unrecovered read error" */ 626 ctl_set_sense(ctsio, 627 /*current_error*/ 1, 628 /*sense_key*/ SSD_KEY_MEDIUM_ERROR, 629 /*asc*/ 0x11, 630 /*ascq*/ 0x00, 631 SSD_ELEM_NONE); 632 } else { 633 /* "Write error - auto reallocation failed" */ 634 ctl_set_sense(ctsio, 635 /*current_error*/ 1, 636 /*sense_key*/ SSD_KEY_MEDIUM_ERROR, 637 /*asc*/ 0x0C, 638 /*ascq*/ 0x02, 639 SSD_ELEM_NONE); 640 } 641 } 642 643 void 644 ctl_set_aborted(struct ctl_scsiio *ctsio) 645 { 646 ctl_set_sense(ctsio, 647 /*current_error*/ 1, 648 /*sense_key*/ SSD_KEY_ABORTED_COMMAND, 649 /*asc*/ 0x45, 650 /*ascq*/ 0x00, 651 SSD_ELEM_NONE); 652 } 653 654 void 655 ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio) 656 { 657 /* "Logical block address out of range" */ 658 ctl_set_sense(ctsio, 659 /*current_error*/ 1, 660 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 661 /*asc*/ 0x21, 662 /*ascq*/ 0x00, 663 SSD_ELEM_NONE); 664 } 665 666 void 667 ctl_set_lun_stopped(struct ctl_scsiio *ctsio) 668 { 669 /* "Logical unit not ready, initializing cmd. required" */ 670 ctl_set_sense(ctsio, 671 /*current_error*/ 1, 672 /*sense_key*/ SSD_KEY_NOT_READY, 673 /*asc*/ 0x04, 674 /*ascq*/ 0x02, 675 SSD_ELEM_NONE); 676 } 677 678 void 679 ctl_set_lun_not_ready(struct ctl_scsiio *ctsio) 680 { 681 /* "Logical unit not ready, manual intervention required" */ 682 ctl_set_sense(ctsio, 683 /*current_error*/ 1, 684 /*sense_key*/ SSD_KEY_NOT_READY, 685 /*asc*/ 0x04, 686 /*ascq*/ 0x05, 687 SSD_ELEM_NONE); 688 } 689 690 void 691 ctl_set_illegal_pr_release(struct ctl_scsiio *ctsio) 692 { 693 /* "Invalid release of persistent reservation" */ 694 ctl_set_sense(ctsio, 695 /*current_error*/ 1, 696 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST, 697 /*asc*/ 0x26, 698 /*ascq*/ 0x04, 699 SSD_ELEM_NONE); 700 } 701 702 void 703 ctl_set_lun_standby(struct ctl_scsiio *ctsio) 704 { 705 /* "Logical unit not ready, target port in standby state" */ 706 ctl_set_sense(ctsio, 707 /*current_error*/ 1, 708 /*sense_key*/ SSD_KEY_NOT_READY, 709 /*asc*/ 0x04, 710 /*ascq*/ 0x0b, 711 SSD_ELEM_NONE); 712 } 713 714 void 715 ctl_set_medium_format_corrupted(struct ctl_scsiio *ctsio) 716 { 717 /* "Medium format corrupted" */ 718 ctl_set_sense(ctsio, 719 /*current_error*/ 1, 720 /*sense_key*/ SSD_KEY_MEDIUM_ERROR, 721 /*asc*/ 0x31, 722 /*ascq*/ 0x00, 723 SSD_ELEM_NONE); 724 } 725 726 void 727 ctl_set_medium_magazine_inaccessible(struct ctl_scsiio *ctsio) 728 { 729 /* "Medium magazine not accessible" */ 730 ctl_set_sense(ctsio, 731 /*current_error*/ 1, 732 /*sense_key*/ SSD_KEY_NOT_READY, 733 /*asc*/ 0x3b, 734 /*ascq*/ 0x11, 735 SSD_ELEM_NONE); 736 } 737 738 void 739 ctl_set_data_phase_error(struct ctl_scsiio *ctsio) 740 { 741 /* "Data phase error" */ 742 ctl_set_sense(ctsio, 743 /*current_error*/ 1, 744 /*sense_key*/ SSD_KEY_NOT_READY, 745 /*asc*/ 0x4b, 746 /*ascq*/ 0x00, 747 SSD_ELEM_NONE); 748 } 749 750 void 751 ctl_set_reservation_conflict(struct ctl_scsiio *ctsio) 752 { 753 struct scsi_sense_data *sense; 754 755 sense = &ctsio->sense_data; 756 memset(sense, 0, sizeof(*sense)); 757 ctsio->scsi_status = SCSI_STATUS_RESERV_CONFLICT; 758 ctsio->sense_len = 0; 759 ctsio->io_hdr.status = CTL_SCSI_ERROR; 760 } 761 762 void 763 ctl_set_queue_full(struct ctl_scsiio *ctsio) 764 { 765 struct scsi_sense_data *sense; 766 767 sense = &ctsio->sense_data; 768 memset(sense, 0, sizeof(*sense)); 769 ctsio->scsi_status = SCSI_STATUS_QUEUE_FULL; 770 ctsio->sense_len = 0; 771 ctsio->io_hdr.status = CTL_SCSI_ERROR; 772 } 773 774 void 775 ctl_set_busy(struct ctl_scsiio *ctsio) 776 { 777 struct scsi_sense_data *sense; 778 779 sense = &ctsio->sense_data; 780 memset(sense, 0, sizeof(*sense)); 781 ctsio->scsi_status = SCSI_STATUS_BUSY; 782 ctsio->sense_len = 0; 783 ctsio->io_hdr.status = CTL_SCSI_ERROR; 784 } 785 786 void 787 ctl_set_success(struct ctl_scsiio *ctsio) 788 { 789 struct scsi_sense_data *sense; 790 791 sense = &ctsio->sense_data; 792 memset(sense, 0, sizeof(*sense)); 793 ctsio->scsi_status = SCSI_STATUS_OK; 794 ctsio->sense_len = 0; 795 ctsio->io_hdr.status = CTL_SUCCESS; 796 } 797