FreeBSD kernel CAM code
ctl_error.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2003-2009 Silicon Graphics International Corp.
5 * Copyright (c) 2011 Spectra Logic Corporation
6 * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * substantially similar to the "NO WARRANTY" disclaimer below
17 * ("Disclaimer") and any redistribution must be conditioned upon
18 * including a substantially similar Disclaimer requirement for further
19 * binary redistribution.
20 *
21 * NO WARRANTY
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGES.
33 *
34 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_error.c#2 $
35 */
36/*
37 * CAM Target Layer error reporting routines.
38 *
39 * Author: Ken Merry <ken@FreeBSD.org>
40 */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD$");
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
48#include <sys/types.h>
49#include <sys/malloc.h>
50#include <sys/lock.h>
51#include <sys/mutex.h>
52#include <sys/condvar.h>
53#include <sys/stddef.h>
54#include <sys/ctype.h>
55#include <sys/sysctl.h>
56#include <machine/stdarg.h>
57
58#include <cam/scsi/scsi_all.h>
59#include <cam/scsi/scsi_da.h>
60#include <cam/ctl/ctl_io.h>
61#include <cam/ctl/ctl.h>
63#include <cam/ctl/ctl_backend.h>
64#include <cam/ctl/ctl_ioctl.h>
65#include <cam/ctl/ctl_error.h>
66#include <cam/ctl/ctl_ha.h>
67#include <cam/ctl/ctl_private.h>
68
69void
70ctl_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
71 void *lunptr, scsi_sense_data_type sense_format, int current_error,
72 int sense_key, int asc, int ascq, va_list ap)
73{
74 struct ctl_lun *lun;
75
76 lun = (struct ctl_lun *)lunptr;
77
78 /*
79 * Determine whether to return fixed or descriptor format sense
80 * data.
81 */
82 if (sense_format == SSD_TYPE_NONE) {
83 /*
84 * SPC-3 and up require some UAs to be returned as fixed.
85 */
86 if (asc == 0x29 || (asc == 0x2A && ascq == 0x01))
87 sense_format = SSD_TYPE_FIXED;
88 else
89 /*
90 * If the format isn't specified, we only return descriptor
91 * sense if the LUN exists and descriptor sense is turned
92 * on for that LUN.
93 */
94 if ((lun != NULL) && (lun->MODE_CTRL.rlec & SCP_DSENSE))
95 sense_format = SSD_TYPE_DESC;
96 else
97 sense_format = SSD_TYPE_FIXED;
98 }
99
100 /*
101 * Determine maximum sense data length to return.
102 */
103 if (*sense_len == 0) {
104 if ((lun != NULL) && (lun->MODE_CTRLE.max_sense != 0))
105 *sense_len = lun->MODE_CTRLE.max_sense;
106 else
107 *sense_len = SSD_FULL_SIZE;
108 }
109
110 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
111 current_error, sense_key, asc, ascq, ap);
112}
113
114void
115ctl_set_sense_data(struct scsi_sense_data *sense_data, u_int *sense_len,
116 void *lunptr, scsi_sense_data_type sense_format, int current_error,
117 int sense_key, int asc, int ascq, ...)
118{
119 va_list ap;
120
121 va_start(ap, ascq);
122 ctl_set_sense_data_va(sense_data, sense_len, lunptr, sense_format,
123 current_error, sense_key, asc, ascq, ap);
124 va_end(ap);
125}
126
127void
128ctl_set_sense(struct ctl_scsiio *ctsio, int current_error, int sense_key,
129 int asc, int ascq, ...)
130{
131 va_list ap;
132 struct ctl_lun *lun;
133 u_int sense_len;
134
135 /*
136 * The LUN can't go away until all of the commands have been
137 * completed. Therefore we can safely access the LUN structure and
138 * flags without the lock.
139 */
140 lun = CTL_LUN(ctsio);
141
142 va_start(ap, ascq);
143 sense_len = 0;
144 ctl_set_sense_data_va(&ctsio->sense_data, &sense_len,
145 lun,
147 current_error,
148 sense_key,
149 asc,
150 ascq,
151 ap);
152 va_end(ap);
153
155 ctsio->sense_len = sense_len;
157}
158
159/*
160 * Transform fixed sense data into descriptor sense data.
161 *
162 * For simplicity's sake, we assume that both sense structures are
163 * SSD_FULL_SIZE. Otherwise, the logic gets more complicated.
164 */
165void
167 struct scsi_sense_data_desc *sense_dest)
168{
169 struct scsi_sense_stream stream_sense;
170 int current_error;
171 u_int sense_len;
172 uint8_t stream_bits;
173
174 bzero(sense_dest, sizeof(*sense_dest));
175
176 if ((sense_src->error_code & SSD_ERRCODE) == SSD_DEFERRED_ERROR)
177 current_error = 0;
178 else
179 current_error = 1;
180
181 bzero(&stream_sense, sizeof(stream_sense));
182
183 /*
184 * Check to see whether any of the tape-specific bits are set. If
185 * so, we'll need a stream sense descriptor.
186 */
187 if (sense_src->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK))
188 stream_bits = sense_src->flags & ~SSD_KEY;
189 else
190 stream_bits = 0;
191
192 /*
193 * Utilize our sense setting routine to do the transform. If a
194 * value is set in the fixed sense data, set it in the descriptor
195 * data. Otherwise, skip it.
196 */
197 sense_len = SSD_FULL_SIZE;
198 ctl_set_sense_data((struct scsi_sense_data *)sense_dest, &sense_len,
199 /*lun*/ NULL,
200 /*sense_format*/ SSD_TYPE_DESC,
201 current_error,
202 /*sense_key*/ sense_src->flags & SSD_KEY,
203 /*asc*/ sense_src->add_sense_code,
204 /*ascq*/ sense_src->add_sense_code_qual,
205
206 /* Information Bytes */
207 (sense_src->error_code & SSD_ERRCODE_VALID) ?
209 sizeof(sense_src->info),
210 sense_src->info,
211
212 /* Command specific bytes */
213 (scsi_4btoul(sense_src->cmd_spec_info) != 0) ?
215 sizeof(sense_src->cmd_spec_info),
216 sense_src->cmd_spec_info,
217
218 /* FRU */
219 (sense_src->fru != 0) ?
221 sizeof(sense_src->fru),
222 &sense_src->fru,
223
224 /* Sense Key Specific */
225 (sense_src->sense_key_spec[0] & SSD_SCS_VALID) ?
227 sizeof(sense_src->sense_key_spec),
228 sense_src->sense_key_spec,
229
230 /* Tape bits */
231 (stream_bits != 0) ?
233 sizeof(stream_bits),
234 &stream_bits,
235
237}
238
239/*
240 * Transform descriptor format sense data into fixed sense data.
241 *
242 * Some data may be lost in translation, because there are descriptors
243 * thant can't be represented as fixed sense data.
244 *
245 * For simplicity's sake, we assume that both sense structures are
246 * SSD_FULL_SIZE. Otherwise, the logic gets more complicated.
247 */
248void
250 struct scsi_sense_data_fixed *sense_dest)
251{
252 int current_error;
253 uint8_t *info_ptr = NULL, *cmd_ptr = NULL, *fru_ptr = NULL;
254 uint8_t *sks_ptr = NULL, *stream_ptr = NULL;
255 int info_size = 0, cmd_size = 0, fru_size = 0;
256 int sks_size = 0, stream_size = 0;
257 int pos;
258 u_int sense_len;
259
260 if ((sense_src->error_code & SSD_ERRCODE) == SSD_DESC_CURRENT_ERROR)
261 current_error = 1;
262 else
263 current_error = 0;
264
265 for (pos = 0; pos < (int)(sense_src->extra_len - 1);) {
266 struct scsi_sense_desc_header *header;
267
268 header = (struct scsi_sense_desc_header *)
269 &sense_src->sense_desc[pos];
270
271 /*
272 * See if this record goes past the end of the sense data.
273 * It shouldn't, but check just in case.
274 */
275 if ((pos + header->length + sizeof(*header)) >
276 sense_src->extra_len)
277 break;
278
279 switch (sense_src->sense_desc[pos]) {
280 case SSD_DESC_INFO: {
281 struct scsi_sense_info *info;
282
283 info = (struct scsi_sense_info *)header;
284
285 info_ptr = info->info;
286 info_size = sizeof(info->info);
287
288 pos += info->length +
289 sizeof(struct scsi_sense_desc_header);
290 break;
291 }
292 case SSD_DESC_COMMAND: {
293 struct scsi_sense_command *cmd;
294
295 cmd = (struct scsi_sense_command *)header;
296 cmd_ptr = cmd->command_info;
297 cmd_size = sizeof(cmd->command_info);
298
299 pos += cmd->length +
300 sizeof(struct scsi_sense_desc_header);
301 break;
302 }
303 case SSD_DESC_FRU: {
304 struct scsi_sense_fru *fru;
305
306 fru = (struct scsi_sense_fru *)header;
307 fru_ptr = &fru->fru;
308 fru_size = sizeof(fru->fru);
309 pos += fru->length +
310 sizeof(struct scsi_sense_desc_header);
311 break;
312 }
313 case SSD_DESC_SKS: {
314 struct scsi_sense_sks *sks;
315
316 sks = (struct scsi_sense_sks *)header;
317 sks_ptr = sks->sense_key_spec;
318 sks_size = sizeof(sks->sense_key_spec);
319
320 pos = sks->length +
321 sizeof(struct scsi_sense_desc_header);
322 break;
323 }
324 case SSD_DESC_STREAM: {
325 struct scsi_sense_stream *stream_sense;
326
327 stream_sense = (struct scsi_sense_stream *)header;
328 stream_ptr = &stream_sense->byte3;
329 stream_size = sizeof(stream_sense->byte3);
330 pos = stream_sense->length +
331 sizeof(struct scsi_sense_desc_header);
332 break;
333 }
334 default:
335 /*
336 * We don't recognize this particular sense
337 * descriptor type, so just skip it.
338 */
339 pos += sizeof(*header) + header->length;
340 break;
341 }
342 }
343
344 sense_len = SSD_FULL_SIZE;
345 ctl_set_sense_data((struct scsi_sense_data *)sense_dest, &sense_len,
346 /*lun*/ NULL,
347 /*sense_format*/ SSD_TYPE_FIXED,
348 current_error,
349 /*sense_key*/ sense_src->sense_key & SSD_KEY,
350 /*asc*/ sense_src->add_sense_code,
351 /*ascq*/ sense_src->add_sense_code_qual,
352
353 /* Information Bytes */
354 (info_ptr != NULL) ? SSD_ELEM_INFO : SSD_ELEM_SKIP,
355 info_size,
356 info_ptr,
357
358 /* Command specific bytes */
359 (cmd_ptr != NULL) ? SSD_ELEM_COMMAND : SSD_ELEM_SKIP,
360 cmd_size,
361 cmd_ptr,
362
363 /* FRU */
364 (fru_ptr != NULL) ? SSD_ELEM_FRU : SSD_ELEM_SKIP,
365 fru_size,
366 fru_ptr,
367
368 /* Sense Key Specific */
369 (sks_ptr != NULL) ? SSD_ELEM_SKS : SSD_ELEM_SKIP,
370 sks_size,
371 sks_ptr,
372
373 /* Tape bits */
374 (stream_ptr != NULL) ? SSD_ELEM_STREAM : SSD_ELEM_SKIP,
375 stream_size,
376 stream_ptr,
377
379}
380
381void
382ctl_set_ua(struct ctl_scsiio *ctsio, int asc, int ascq)
383{
384 ctl_set_sense(ctsio,
385 /*current_error*/ 1,
386 /*sense_key*/ SSD_KEY_UNIT_ATTENTION,
387 asc,
388 ascq,
390}
391
392static void
393ctl_ua_to_ascq(struct ctl_lun *lun, ctl_ua_type ua_to_build, int *asc,
394 int *ascq, ctl_ua_type *ua_to_clear, uint8_t **info)
395{
396
397 switch (ua_to_build) {
398 case CTL_UA_POWERON:
399 /* 29h/01h POWER ON OCCURRED */
400 *asc = 0x29;
401 *ascq = 0x01;
402 *ua_to_clear = ~0;
403 break;
404 case CTL_UA_BUS_RESET:
405 /* 29h/02h SCSI BUS RESET OCCURRED */
406 *asc = 0x29;
407 *ascq = 0x02;
408 *ua_to_clear = ~0;
409 break;
411 /* 29h/03h BUS DEVICE RESET FUNCTION OCCURRED*/
412 *asc = 0x29;
413 *ascq = 0x03;
414 *ua_to_clear = ~0;
415 break;
417 /* 29h/07h I_T NEXUS LOSS OCCURRED */
418 *asc = 0x29;
419 *ascq = 0x07;
420 *ua_to_clear = ~0;
421 break;
422 case CTL_UA_LUN_RESET:
423 /* 29h/00h POWER ON, RESET, OR BUS DEVICE RESET OCCURRED */
424 /*
425 * Since we don't have a specific ASC/ASCQ pair for a LUN
426 * reset, just return the generic reset code.
427 */
428 *asc = 0x29;
429 *ascq = 0x00;
430 break;
432 /* 3Fh/0Eh REPORTED LUNS DATA HAS CHANGED */
433 *asc = 0x3F;
434 *ascq = 0x0E;
435 break;
437 /* 2Ah/01h MODE PARAMETERS CHANGED */
438 *asc = 0x2A;
439 *ascq = 0x01;
440 break;
442 /* 2Ah/02h LOG PARAMETERS CHANGED */
443 *asc = 0x2A;
444 *ascq = 0x02;
445 break;
447 /* 3Fh/03h INQUIRY DATA HAS CHANGED */
448 *asc = 0x3F;
449 *ascq = 0x03;
450 break;
452 /* 2Ah/03h RESERVATIONS PREEMPTED */
453 *asc = 0x2A;
454 *ascq = 0x03;
455 break;
457 /* 2Ah/04h RESERVATIONS RELEASED */
458 *asc = 0x2A;
459 *ascq = 0x04;
460 break;
462 /* 2Ah/05h REGISTRATIONS PREEMPTED */
463 *asc = 0x2A;
464 *ascq = 0x05;
465 break;
467 /* 2Ah/06h ASYMMETRIC ACCESS STATE CHANGED */
468 *asc = 0x2A;
469 *ascq = 0x06;
470 break;
472 /* 2Ah/09h CAPACITY DATA HAS CHANGED */
473 *asc = 0x2A;
474 *ascq = 0x09;
475 break;
477 /* 38h/07h THIN PROVISIONING SOFT THRESHOLD REACHED */
478 *asc = 0x38;
479 *ascq = 0x07;
480 *info = lun->ua_tpt_info;
481 break;
483 /* 28h/00h NOT READY TO READY CHANGE, MEDIUM MAY HAVE CHANGED */
484 *asc = 0x28;
485 *ascq = 0x00;
486 break;
487 case CTL_UA_IE:
488 /* Informational exception */
489 *asc = lun->ie_asc;
490 *ascq = lun->ie_ascq;
491 break;
492 default:
493 panic("%s: Unknown UA %x", __func__, ua_to_build);
494 }
495}
496
498ctl_build_qae(struct ctl_lun *lun, uint32_t initidx, uint8_t *resp)
499{
500 ctl_ua_type ua;
501 ctl_ua_type ua_to_build, ua_to_clear;
502 uint8_t *info;
503 int asc, ascq;
504 uint32_t p, i;
505
506 mtx_assert(&lun->lun_lock, MA_OWNED);
507 p = initidx / CTL_MAX_INIT_PER_PORT;
508 i = initidx % CTL_MAX_INIT_PER_PORT;
509 if (lun->pending_ua[p] == NULL)
510 ua = CTL_UA_POWERON;
511 else
512 ua = lun->pending_ua[p][i];
513 if (ua == CTL_UA_NONE)
514 return (CTL_UA_NONE);
515
516 ua_to_build = (1 << (ffs(ua) - 1));
517 ua_to_clear = ua_to_build;
518 info = NULL;
519 ctl_ua_to_ascq(lun, ua_to_build, &asc, &ascq, &ua_to_clear, &info);
520
521 resp[0] = SSD_KEY_UNIT_ATTENTION;
522 if (ua_to_build == ua)
523 resp[0] |= 0x10;
524 else
525 resp[0] |= 0x20;
526 resp[1] = asc;
527 resp[2] = ascq;
528 return (ua_to_build);
529}
530
532ctl_build_ua(struct ctl_lun *lun, uint32_t initidx,
533 struct scsi_sense_data *sense, u_int *sense_len,
534 scsi_sense_data_type sense_format)
535{
536 ctl_ua_type *ua;
537 ctl_ua_type ua_to_build, ua_to_clear;
538 uint8_t *info;
539 int asc, ascq;
540 uint32_t p, i;
541
542 mtx_assert(&lun->lun_lock, MA_OWNED);
543 mtx_assert(&lun->ctl_softc->ctl_lock, MA_NOTOWNED);
544 p = initidx / CTL_MAX_INIT_PER_PORT;
545 if ((ua = lun->pending_ua[p]) == NULL) {
546 mtx_unlock(&lun->lun_lock);
547 ua = malloc(sizeof(ctl_ua_type) * CTL_MAX_INIT_PER_PORT,
548 M_CTL, M_WAITOK);
549 mtx_lock(&lun->lun_lock);
550 if (lun->pending_ua[p] == NULL) {
551 lun->pending_ua[p] = ua;
552 for (i = 0; i < CTL_MAX_INIT_PER_PORT; i++)
553 ua[i] = CTL_UA_POWERON;
554 } else {
555 free(ua, M_CTL);
556 ua = lun->pending_ua[p];
557 }
558 }
559 i = initidx % CTL_MAX_INIT_PER_PORT;
560 if (ua[i] == CTL_UA_NONE)
561 return (CTL_UA_NONE);
562
563 ua_to_build = (1 << (ffs(ua[i]) - 1));
564 ua_to_clear = ua_to_build;
565 info = NULL;
566 ctl_ua_to_ascq(lun, ua_to_build, &asc, &ascq, &ua_to_clear, &info);
567
568 ctl_set_sense_data(sense, sense_len, lun, sense_format, 1,
569 /*sense_key*/ SSD_KEY_UNIT_ATTENTION, asc, ascq,
570 ((info != NULL) ? SSD_ELEM_INFO : SSD_ELEM_SKIP), 8, info,
572
573 /* We're reporting this UA, so clear it */
574 ua[i] &= ~ua_to_clear;
575
576 if (ua_to_build == CTL_UA_LUN_CHANGE) {
577 mtx_unlock(&lun->lun_lock);
578 mtx_lock(&lun->ctl_softc->ctl_lock);
579 ctl_clr_ua_allluns(lun->ctl_softc, initidx, ua_to_build);
580 mtx_unlock(&lun->ctl_softc->ctl_lock);
581 mtx_lock(&lun->lun_lock);
582 } else if (ua_to_build == CTL_UA_THIN_PROV_THRES &&
583 (lun->MODE_LBP.main.flags & SLBPP_SITUA) != 0) {
584 ctl_clr_ua_all(lun, -1, ua_to_build);
585 }
586
587 return (ua_to_build);
588}
589
590void
592{
593 /* OVERLAPPED COMMANDS ATTEMPTED */
594 ctl_set_sense(ctsio,
595 /*current_error*/ 1,
596 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
597 /*asc*/ 0x4E,
598 /*ascq*/ 0x00,
600}
601
602void
603ctl_set_overlapped_tag(struct ctl_scsiio *ctsio, uint8_t tag)
604{
605 /* TAGGED OVERLAPPED COMMANDS (NN = QUEUE TAG) */
606 ctl_set_sense(ctsio,
607 /*current_error*/ 1,
608 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
609 /*asc*/ 0x4D,
610 /*ascq*/ tag,
612}
613
614/*
615 * Tell the user that there was a problem with the command or data he sent.
616 */
617void
618ctl_set_invalid_field(struct ctl_scsiio *ctsio, int sks_valid, int command,
619 int field, int bit_valid, int bit)
620{
621 uint8_t sks[3];
622 int asc;
623
624 if (command != 0) {
625 /* "Invalid field in CDB" */
626 asc = 0x24;
627 } else {
628 /* "Invalid field in parameter list" */
629 asc = 0x26;
630 }
631
632 if (sks_valid) {
633 sks[0] = SSD_SCS_VALID;
634 if (command)
635 sks[0] |= SSD_FIELDPTR_CMD;
636 scsi_ulto2b(field, &sks[1]);
637
638 if (bit_valid)
639 sks[0] |= SSD_BITPTR_VALID | bit;
640 }
641
642 ctl_set_sense(ctsio,
643 /*current_error*/ 1,
644 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
645 asc,
646 /*ascq*/ 0x00,
647 /*type*/ (sks_valid != 0) ? SSD_ELEM_SKS : SSD_ELEM_SKIP,
648 /*size*/ sizeof(sks),
649 /*data*/ sks,
651}
652void
654{
655
656 /* "Invalid field in command information unit" */
657 ctl_set_sense(ctsio,
658 /*current_error*/ 1,
659 /*sense_key*/ SSD_KEY_ABORTED_COMMAND,
660 /*ascq*/ 0x0E,
661 /*ascq*/ 0x03,
663}
664
665void
667{
668 uint8_t sks[3];
669
671 scsi_ulto2b(0, &sks[1]);
672
673 /* "Invalid command operation code" */
674 ctl_set_sense(ctsio,
675 /*current_error*/ 1,
676 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
677 /*asc*/ 0x20,
678 /*ascq*/ 0x00,
679 /*type*/ SSD_ELEM_SKS,
680 /*size*/ sizeof(sks),
681 /*data*/ sks,
683}
684
685void
687{
688 /* "Parameter list length error" */
689 ctl_set_sense(ctsio,
690 /*current_error*/ 1,
691 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
692 /*asc*/ 0x1a,
693 /*ascq*/ 0x00,
695}
696
697void
699{
700 /* Vendor unique "Somebody already is locked" */
701 ctl_set_sense(ctsio,
702 /*current_error*/ 1,
703 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
704 /*asc*/ 0x81,
705 /*ascq*/ 0x00,
707}
708
709void
711{
712 /* "Logical unit not supported" */
713 ctl_set_sense(ctsio,
714 /*current_error*/ 1,
715 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
716 /*asc*/ 0x25,
717 /*ascq*/ 0x00,
719}
720
721void
722ctl_set_internal_failure(struct ctl_scsiio *ctsio, int sks_valid,
723 uint16_t retry_count)
724{
725 uint8_t sks[3];
726
727 if (sks_valid) {
728 sks[0] = SSD_SCS_VALID;
729 sks[1] = (retry_count >> 8) & 0xff;
730 sks[2] = retry_count & 0xff;
731 }
732
733 /* "Internal target failure" */
734 ctl_set_sense(ctsio,
735 /*current_error*/ 1,
736 /*sense_key*/ SSD_KEY_HARDWARE_ERROR,
737 /*asc*/ 0x44,
738 /*ascq*/ 0x00,
739 /*type*/ (sks_valid != 0) ? SSD_ELEM_SKS : SSD_ELEM_SKIP,
740 /*size*/ sizeof(sks),
741 /*data*/ sks,
743}
744
745void
746ctl_set_medium_error(struct ctl_scsiio *ctsio, int read)
747{
748 if (read) {
749 /* "Unrecovered read error" */
750 ctl_set_sense(ctsio,
751 /*current_error*/ 1,
752 /*sense_key*/ SSD_KEY_MEDIUM_ERROR,
753 /*asc*/ 0x11,
754 /*ascq*/ 0x00,
756 } else {
757 /* "Write error - auto reallocation failed" */
758 ctl_set_sense(ctsio,
759 /*current_error*/ 1,
760 /*sense_key*/ SSD_KEY_MEDIUM_ERROR,
761 /*asc*/ 0x0C,
762 /*ascq*/ 0x02,
764 }
765}
766
767void
769{
770 ctl_set_sense(ctsio,
771 /*current_error*/ 1,
772 /*sense_key*/ SSD_KEY_ABORTED_COMMAND,
773 /*asc*/ 0x45,
774 /*ascq*/ 0x00,
776}
777
778void
779ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio, uint64_t lba)
780{
781 uint8_t info[8];
782
783 scsi_u64to8b(lba, info);
784
785 /* "Logical block address out of range" */
786 ctl_set_sense(ctsio,
787 /*current_error*/ 1,
788 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
789 /*asc*/ 0x21,
790 /*ascq*/ 0x00,
791 /*type*/ (lba != 0) ? SSD_ELEM_INFO : SSD_ELEM_SKIP,
792 /*size*/ sizeof(info), /*data*/ &info,
794}
795
796void
798{
799 /* "Logical unit not ready, initializing cmd. required" */
800 ctl_set_sense(ctsio,
801 /*current_error*/ 1,
802 /*sense_key*/ SSD_KEY_NOT_READY,
803 /*asc*/ 0x04,
804 /*ascq*/ 0x02,
806}
807
808void
810{
811 /* "Logical unit not ready, manual intervention required" */
812 ctl_set_sense(ctsio,
813 /*current_error*/ 1,
814 /*sense_key*/ SSD_KEY_NOT_READY,
815 /*asc*/ 0x04,
816 /*ascq*/ 0x03,
818}
819
820void
822{
823 /* "Medium not present - tray open" */
824 ctl_set_sense(ctsio,
825 /*current_error*/ 1,
826 /*sense_key*/ SSD_KEY_NOT_READY,
827 /*asc*/ 0x3A,
828 /*ascq*/ 0x02,
830}
831
832void
834{
835 /* "Medium not present - tray closed" */
836 ctl_set_sense(ctsio,
837 /*current_error*/ 1,
838 /*sense_key*/ SSD_KEY_NOT_READY,
839 /*asc*/ 0x3A,
840 /*ascq*/ 0x01,
842}
843
844void
846{
847 /* "Invalid release of persistent reservation" */
848 ctl_set_sense(ctsio,
849 /*current_error*/ 1,
850 /*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
851 /*asc*/ 0x26,
852 /*ascq*/ 0x04,
854}
855
856void
858{
859 /* "Logical unit not ready, asymmetric access state transition" */
860 ctl_set_sense(ctsio,
861 /*current_error*/ 1,
862 /*sense_key*/ SSD_KEY_NOT_READY,
863 /*asc*/ 0x04,
864 /*ascq*/ 0x0a,
866}
867
868void
870{
871 /* "Logical unit not ready, target port in standby state" */
872 ctl_set_sense(ctsio,
873 /*current_error*/ 1,
874 /*sense_key*/ SSD_KEY_NOT_READY,
875 /*asc*/ 0x04,
876 /*ascq*/ 0x0b,
878}
879
880void
882{
883 /* "Logical unit not ready, target port in unavailable state" */
884 ctl_set_sense(ctsio,
885 /*current_error*/ 1,
886 /*sense_key*/ SSD_KEY_NOT_READY,
887 /*asc*/ 0x04,
888 /*ascq*/ 0x0c,
890}
891
892void
894{
895 /* "Medium format corrupted" */
896 ctl_set_sense(ctsio,
897 /*current_error*/ 1,
898 /*sense_key*/ SSD_KEY_MEDIUM_ERROR,
899 /*asc*/ 0x31,
900 /*ascq*/ 0x00,
902}
903
904void
906{
907 /* "Medium magazine not accessible" */
908 ctl_set_sense(ctsio,
909 /*current_error*/ 1,
910 /*sense_key*/ SSD_KEY_NOT_READY,
911 /*asc*/ 0x3b,
912 /*ascq*/ 0x11,
914}
915
916void
918{
919 /* "Data phase error" */
920 ctl_set_sense(ctsio,
921 /*current_error*/ 1,
922 /*sense_key*/ SSD_KEY_NOT_READY,
923 /*asc*/ 0x4b,
924 /*ascq*/ 0x00,
926}
927
928void
930{
931
933 ctsio->sense_len = 0;
935}
936
937void
939{
940
942 ctsio->sense_len = 0;
944}
945
946void
948{
949
951 ctsio->sense_len = 0;
953}
954
955void
957{
958
960 ctsio->sense_len = 0;
962}
963
964void
966{
967 /* "Hardware write protected" */
968 ctl_set_sense(ctsio,
969 /*current_error*/ 1,
970 /*sense_key*/ SSD_KEY_DATA_PROTECT,
971 /*asc*/ 0x27,
972 /*ascq*/ 0x01,
974}
975
976void
978{
979 /* "Space allocation failed write protect" */
980 ctl_set_sense(ctsio,
981 /*current_error*/ 1,
982 /*sense_key*/ SSD_KEY_DATA_PROTECT,
983 /*asc*/ 0x27,
984 /*ascq*/ 0x07,
986}
987
988void
990{
991
993 ctsio->sense_len = 0;
994 ctsio->io_hdr.status = CTL_SUCCESS;
995}
void ctl_clr_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua)
Definition: ctl.c:1863
void ctl_clr_ua_allluns(struct ctl_softc *ctl_softc, uint32_t initidx, ctl_ua_type ua_type)
Definition: ctl.c:1881
ctl_ua_type
Definition: ctl.h:110
@ CTL_UA_LUN_RESET
Definition: ctl.h:116
@ CTL_UA_POWERON
Definition: ctl.h:112
@ CTL_UA_THIN_PROV_THRES
Definition: ctl.h:126
@ CTL_UA_ASYM_ACC_CHANGE
Definition: ctl.h:124
@ CTL_UA_IE
Definition: ctl.h:128
@ CTL_UA_BUS_RESET
Definition: ctl.h:113
@ CTL_UA_INQ_CHANGE
Definition: ctl.h:120
@ CTL_UA_RES_RELEASE
Definition: ctl.h:122
@ CTL_UA_I_T_NEXUS_LOSS
Definition: ctl.h:115
@ CTL_UA_NONE
Definition: ctl.h:111
@ CTL_UA_TARG_RESET
Definition: ctl.h:114
@ CTL_UA_MEDIUM_CHANGE
Definition: ctl.h:127
@ CTL_UA_CAPACITY_CHANGE
Definition: ctl.h:125
@ CTL_UA_MODE_CHANGE
Definition: ctl.h:118
@ CTL_UA_LUN_CHANGE
Definition: ctl.h:117
@ CTL_UA_LOG_CHANGE
Definition: ctl.h:119
@ CTL_UA_RES_PREEMPT
Definition: ctl.h:121
@ CTL_UA_REG_PREEMPT
Definition: ctl.h:123
void ctl_set_queue_full(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:938
void ctl_set_hw_write_protected(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:965
ctl_ua_type ctl_build_qae(struct ctl_lun *lun, uint32_t initidx, uint8_t *resp)
Definition: ctl_error.c:498
void ctl_set_task_aborted(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:956
void ctl_set_space_alloc_fail(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:977
void ctl_set_sense_data(struct scsi_sense_data *sense_data, u_int *sense_len, void *lunptr, scsi_sense_data_type sense_format, int current_error, int sense_key, int asc, int ascq,...)
Definition: ctl_error.c:115
void ctl_set_data_phase_error(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:917
void ctl_set_lun_stopped(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:797
ctl_ua_type ctl_build_ua(struct ctl_lun *lun, uint32_t initidx, struct scsi_sense_data *sense, u_int *sense_len, scsi_sense_data_type sense_format)
Definition: ctl_error.c:532
void ctl_set_medium_format_corrupted(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:893
void ctl_set_lun_unavail(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:881
void ctl_set_invalid_field(struct ctl_scsiio *ctsio, int sks_valid, int command, int field, int bit_valid, int bit)
Definition: ctl_error.c:618
void ctl_set_reservation_conflict(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:929
void ctl_set_success(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:989
__FBSDID("$FreeBSD$")
void ctl_set_medium_error(struct ctl_scsiio *ctsio, int read)
Definition: ctl_error.c:746
void ctl_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len, void *lunptr, scsi_sense_data_type sense_format, int current_error, int sense_key, int asc, int ascq, va_list ap)
Definition: ctl_error.c:70
void ctl_sense_to_desc(struct scsi_sense_data_fixed *sense_src, struct scsi_sense_data_desc *sense_dest)
Definition: ctl_error.c:166
void ctl_set_lun_no_media(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:833
void ctl_set_param_len_error(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:686
void ctl_set_ua(struct ctl_scsiio *ctsio, int asc, int ascq)
Definition: ctl_error.c:382
void ctl_set_unsupported_lun(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:710
void ctl_set_illegal_pr_release(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:845
void ctl_sense_to_fixed(struct scsi_sense_data_desc *sense_src, struct scsi_sense_data_fixed *sense_dest)
Definition: ctl_error.c:249
void ctl_set_internal_failure(struct ctl_scsiio *ctsio, int sks_valid, uint16_t retry_count)
Definition: ctl_error.c:722
void ctl_set_lun_int_reqd(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:809
void ctl_set_invalid_opcode(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:666
void ctl_set_lba_out_of_range(struct ctl_scsiio *ctsio, uint64_t lba)
Definition: ctl_error.c:779
void ctl_set_lun_ejected(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:821
void ctl_set_medium_magazine_inaccessible(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:905
void ctl_set_already_locked(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:698
void ctl_set_lun_transit(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:857
void ctl_set_overlapped_tag(struct ctl_scsiio *ctsio, uint8_t tag)
Definition: ctl_error.c:603
void ctl_set_lun_standby(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:869
static void ctl_ua_to_ascq(struct ctl_lun *lun, ctl_ua_type ua_to_build, int *asc, int *ascq, ctl_ua_type *ua_to_clear, uint8_t **info)
Definition: ctl_error.c:393
void ctl_set_busy(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:947
void ctl_set_sense(struct ctl_scsiio *ctsio, int current_error, int sense_key, int asc, int ascq,...)
Definition: ctl_error.c:128
void ctl_set_invalid_field_ciu(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:653
void ctl_set_overlapped_cmd(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:591
void ctl_set_aborted(struct ctl_scsiio *ctsio)
Definition: ctl_error.c:768
@ CTL_SUCCESS
Definition: ctl_io.h:70
@ CTL_AUTOSENSE
Definition: ctl_io.h:77
@ CTL_SCSI_ERROR
Definition: ctl_io.h:74
@ CTL_CMD_ABORTED
Definition: ctl_io.h:75
#define CTL_LUN(io)
Definition: ctl_io.h:166
#define CTL_MAX_INIT_PER_PORT
Definition: ctl_ioctl.h:67
void scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len, scsi_sense_data_type sense_format, int current_error, int sense_key, int asc, int ascq, va_list ap)
Definition: scsi_all.c:4015
#define SSD_KEY_UNIT_ATTENTION
Definition: scsi_all.h:3282
#define SCSI_STATUS_BUSY
Definition: scsi_all.h:3694
#define SSD_DESC_STREAM
Definition: scsi_all.h:3492
#define SSD_KEY_HARDWARE_ERROR
Definition: scsi_all.h:3280
#define SSD_DESC_CURRENT_ERROR
Definition: scsi_all.h:3325
#define SSD_KEY_ABORTED_COMMAND
Definition: scsi_all.h:3287
#define SCSI_STATUS_CHECK_COND
Definition: scsi_all.h:3692
#define SSD_FILEMARK
Definition: scsi_all.h:3295
#define SSD_DESC_COMMAND
Definition: scsi_all.h:3383
#define SSD_DESC_INFO
Definition: scsi_all.h:3362
#define SSD_DESC_FRU
Definition: scsi_all.h:3477
scsi_sense_data_type
Definition: scsi_all.h:3226
@ SSD_TYPE_DESC
Definition: scsi_all.h:3229
@ SSD_TYPE_NONE
Definition: scsi_all.h:3227
@ SSD_TYPE_FIXED
Definition: scsi_all.h:3228
static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
Definition: scsi_all.h:4374
#define SSD_DESC_SKS
Definition: scsi_all.h:3398
#define SCP_DSENSE
Definition: scsi_all.h:714
#define SSD_DEFERRED_ERROR
Definition: scsi_all.h:3271
#define SSD_BITPTR_VALID
Definition: scsi_all.h:3305
#define SSD_KEY_NOT_READY
Definition: scsi_all.h:3278
#define SLBPP_SITUA
Definition: scsi_all.h:849
#define SSD_KEY
Definition: scsi_all.h:3275
#define SSD_KEY_MEDIUM_ERROR
Definition: scsi_all.h:3279
static __inline uint32_t scsi_4btoul(const uint8_t *bytes)
Definition: scsi_all.h:4447
#define SSD_ILI
Definition: scsi_all.h:3293
#define SSD_EOM
Definition: scsi_all.h:3294
#define SCSI_STATUS_OK
Definition: scsi_all.h:3691
#define SSD_FIELDPTR_CMD
Definition: scsi_all.h:3304
#define SSD_SCS_VALID
Definition: scsi_all.h:3303
static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
Definition: scsi_all.h:4401
#define SCSI_STATUS_TASK_ABORTED
Definition: scsi_all.h:3701
#define SCSI_STATUS_RESERV_CONFLICT
Definition: scsi_all.h:3697
#define SSD_ERRCODE
Definition: scsi_all.h:3269
#define SSD_KEY_ILLEGAL_REQUEST
Definition: scsi_all.h:3281
#define SSD_FULL_SIZE
Definition: scsi_all.h:3251
#define SSD_KEY_DATA_PROTECT
Definition: scsi_all.h:3283
@ SSD_ELEM_INFO
Definition: scsi_all.h:3238
@ SSD_ELEM_SKS
Definition: scsi_all.h:3236
@ SSD_ELEM_COMMAND
Definition: scsi_all.h:3237
@ SSD_ELEM_NONE
Definition: scsi_all.h:3233
@ SSD_ELEM_SKIP
Definition: scsi_all.h:3234
@ SSD_ELEM_STREAM
Definition: scsi_all.h:3240
@ SSD_ELEM_FRU
Definition: scsi_all.h:3239
#define SSD_ERRCODE_VALID
Definition: scsi_all.h:3272
#define SCSI_STATUS_QUEUE_FULL
Definition: scsi_all.h:3699
uint32_t status
Definition: ctl_io.h:229
uint8_t ie_ascq
Definition: ctl_private.h:399
struct mtx lun_lock
Definition: ctl_private.h:379
ctl_lun_flags flags
Definition: ctl_private.h:381
ctl_ua_type ** pending_ua
Definition: ctl_private.h:395
uint64_t lun
Definition: ctl_private.h:380
struct ctl_softc * ctl_softc
Definition: ctl_private.h:384
uint8_t ua_tpt_info[8]
Definition: ctl_private.h:396
uint8_t ie_asc
Definition: ctl_private.h:398
struct scsi_sense_data sense_data
Definition: ctl_io.h:326
struct ctl_io_hdr io_hdr
Definition: ctl_io.h:275
uint8_t scsi_status
Definition: ctl_io.h:328
uint8_t sense_len
Definition: ctl_io.h:327
struct mtx ctl_lock
Definition: ctl_private.h:437
uint8_t command_info[8]
Definition: scsi_all.h:3386
uint8_t sense_desc[0]
Definition: scsi_all.h:3338
uint8_t add_sense_code_qual
Definition: scsi_all.h:3329
uint8_t add_sense_code
Definition: scsi_all.h:3328
u_int8_t add_sense_code_qual
Definition: scsi_all.h:3300
u_int8_t add_sense_code
Definition: scsi_all.h:3299
u_int8_t info[4]
Definition: scsi_all.h:3296
u_int8_t sense_key_spec[3]
Definition: scsi_all.h:3302
u_int8_t cmd_spec_info[4]
Definition: scsi_all.h:3298
uint8_t fru
Definition: scsi_all.h:3480
uint8_t info[8]
Definition: scsi_all.h:3367
uint8_t sense_key_spec[3]
Definition: scsi_all.h:3401
uint8_t length
Definition: scsi_all.h:3399