17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55c46c6a0Spd * Common Development and Distribution License (the "License"). 65c46c6a0Spd * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*30ab6db6Slh * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 235c46c6a0Spd * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_SCSI_IMPL_SENSE_H 277c478bd9Sstevel@tonic-gate #define _SYS_SCSI_IMPL_SENSE_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 307c478bd9Sstevel@tonic-gate extern "C" { 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Implementation Variant defines 357c478bd9Sstevel@tonic-gate * for SCSI Sense Information 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * These are 'pseudo' sense keys for common Sun implementation driver 407c478bd9Sstevel@tonic-gate * detected errors. Note that they start out as being higher than the 417c478bd9Sstevel@tonic-gate * legal key numbers for standard SCSI. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define SUN_KEY_FATAL 0x10 /* driver, scsi handshake failure */ 457c478bd9Sstevel@tonic-gate #define SUN_KEY_TIMEOUT 0x11 /* driver, command timeout */ 467c478bd9Sstevel@tonic-gate #define SUN_KEY_EOF 0x12 /* driver, eof hit */ 477c478bd9Sstevel@tonic-gate #define SUN_KEY_EOT 0x13 /* driver, eot hit */ 487c478bd9Sstevel@tonic-gate #define SUN_KEY_LENGTH 0x14 /* driver, length error */ 497c478bd9Sstevel@tonic-gate #define SUN_KEY_BOT 0x15 /* driver, bot hit */ 507c478bd9Sstevel@tonic-gate #define SUN_KEY_WRONGMEDIA 0x16 /* driver, wrong tape media */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define NUM_IMPL_SENSE_KEYS 7 /* seven extra keys */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Common sense length allocation sufficient for this implementation. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #define SENSE_LENGTH \ 597c478bd9Sstevel@tonic-gate (roundup(sizeof (struct scsi_extended_sense), sizeof (int))) 607c478bd9Sstevel@tonic-gate 61*30ab6db6Slh /* 62*30ab6db6Slh * Per SPC-3 standard, the maximum length of sense data is 252 bytes. 63*30ab6db6Slh */ 64*30ab6db6Slh #define MAX_SENSE_LENGTH 252 65*30ab6db6Slh 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Minimum useful Sense Length value 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #define SUN_MIN_SENSE_LENGTH 4 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * Specific variants to the Extended Sense structure. 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * Defines for: 767c478bd9Sstevel@tonic-gate * Emulex MD21 SCSI/ESDI Controller 777c478bd9Sstevel@tonic-gate * Emulex MT02 SCSI/QIC-36 Controller. 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * 1) The Emulex controllers put error class and error code into the byte 807c478bd9Sstevel@tonic-gate * right after the 'additional sense length' field in Extended Sense. 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * 2) Except that some people state that this isn't so for the MD21- only 837c478bd9Sstevel@tonic-gate * the MT02. 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define emulex_ercl_ercd es_cmd_info[0] 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * 2) These are valid on Extended Sense for the MD21, FORMAT command only: 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define emulex_cyl_msb es_info_1 937c478bd9Sstevel@tonic-gate #define emulex_cyl_lsb es_info_2 947c478bd9Sstevel@tonic-gate #define emulex_head_num es_info_3 957c478bd9Sstevel@tonic-gate #define emulex_sect_num es_info_4 967c478bd9Sstevel@tonic-gate 975c46c6a0Spd struct scsi_descr_template { 985c46c6a0Spd uchar_t sdt_descr_type; 995c46c6a0Spd uchar_t sdt_addl_length; 1005c46c6a0Spd }; 1015c46c6a0Spd 1025c46c6a0Spd /* 1035c46c6a0Spd * Function prototypes for descriptor-format sense data functions 1045c46c6a0Spd */ 1055c46c6a0Spd 1065c46c6a0Spd uint8_t *scsi_find_sense_descr(uint8_t *sense_buffer, int sense_buf_len, 1075c46c6a0Spd int descr_type); 1085c46c6a0Spd 1095c46c6a0Spd /* 1105c46c6a0Spd * Function prototypes for format-neutral sense data functions 1115c46c6a0Spd */ 1125c46c6a0Spd 1135c46c6a0Spd uint8_t scsi_sense_key(uint8_t *sense_buffer); 1145c46c6a0Spd 1155c46c6a0Spd uint8_t scsi_sense_asc(uint8_t *sense_buffer); 1165c46c6a0Spd 1175c46c6a0Spd uint8_t scsi_sense_ascq(uint8_t *sense_buffer); 1185c46c6a0Spd 1195c46c6a0Spd boolean_t scsi_sense_info_uint64(uint8_t *sense_buffer, 1205c46c6a0Spd int sense_buf_len, uint64_t *information); 1215c46c6a0Spd 1225c46c6a0Spd boolean_t scsi_sense_cmdspecific_uint64(uint8_t *sense_buffer, 1235c46c6a0Spd int sense_buf_len, uint64_t *cmd_spec_info); 1245c46c6a0Spd 1255c46c6a0Spd void scsi_ext_sense_fields(uint8_t *sense_buffer, int sense_buf_len, 1265c46c6a0Spd uint8_t **information, uint8_t **cmd_spec_info, uint8_t **fru_code, 1275c46c6a0Spd uint8_t **sk_specific, uint8_t **stream_flags); 1285c46c6a0Spd 1295c46c6a0Spd int scsi_validate_sense(uint8_t *sense_buffer, int sense_buf_len, int *flags); 1305c46c6a0Spd 1315c46c6a0Spd /* 1325c46c6a0Spd * Return codes for scsi_validate_sense 1335c46c6a0Spd */ 1345c46c6a0Spd 1355c46c6a0Spd #define SENSE_UNUSABLE 0 1365c46c6a0Spd #define SENSE_FIXED_FORMAT 1 1375c46c6a0Spd #define SENSE_DESCR_FORMAT 2 1385c46c6a0Spd 1395c46c6a0Spd /* 1405c46c6a0Spd * Flags from scsi_validate_sense 1415c46c6a0Spd */ 1425c46c6a0Spd 1435c46c6a0Spd #define SNS_BUF_OVERFLOW 1 /* Sense buffer too small */ 1445c46c6a0Spd #define SNS_BUF_DEFERRED 2 /* Sense data is for prior operation */ 1455c46c6a0Spd 1467c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate #endif 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate #endif /* _SYS_SCSI_IMPL_SENSE_H */ 151