xref: /titanic_41/usr/src/uts/common/sys/scsi/impl/sense.h (revision 30ab6db6f19a1f9cb466e0b45b221f6d19ca557c)
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
55c46c6a0Spd144616  * Common Development and Distribution License (the "License").
65c46c6a0Spd144616  * 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*30ab6db6Slh195018  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
235c46c6a0Spd144616  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Implementation Variant defines
377c478bd9Sstevel@tonic-gate  * for SCSI Sense Information
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * These are 'pseudo' sense keys for common Sun implementation driver
427c478bd9Sstevel@tonic-gate  * detected errors. Note that they start out as being higher than the
437c478bd9Sstevel@tonic-gate  * legal key numbers for standard SCSI.
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	SUN_KEY_FATAL		0x10	/* driver, scsi handshake failure */
477c478bd9Sstevel@tonic-gate #define	SUN_KEY_TIMEOUT		0x11	/* driver, command timeout */
487c478bd9Sstevel@tonic-gate #define	SUN_KEY_EOF		0x12	/* driver, eof hit */
497c478bd9Sstevel@tonic-gate #define	SUN_KEY_EOT		0x13	/* driver, eot hit */
507c478bd9Sstevel@tonic-gate #define	SUN_KEY_LENGTH		0x14	/* driver, length error */
517c478bd9Sstevel@tonic-gate #define	SUN_KEY_BOT		0x15	/* driver, bot hit */
527c478bd9Sstevel@tonic-gate #define	SUN_KEY_WRONGMEDIA	0x16	/* driver, wrong tape media */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	NUM_IMPL_SENSE_KEYS	7	/* seven extra keys */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * Common sense length allocation sufficient for this implementation.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	SENSE_LENGTH	\
617c478bd9Sstevel@tonic-gate 	(roundup(sizeof (struct scsi_extended_sense), sizeof (int)))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
64*30ab6db6Slh195018  * Per SPC-3 standard, the maximum length of sense data is 252 bytes.
65*30ab6db6Slh195018  */
66*30ab6db6Slh195018 #define	MAX_SENSE_LENGTH	252
67*30ab6db6Slh195018 
68*30ab6db6Slh195018 /*
697c478bd9Sstevel@tonic-gate  * Minimum useful Sense Length value
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #define	SUN_MIN_SENSE_LENGTH	4
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Specific variants to the Extended Sense structure.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * Defines for:
787c478bd9Sstevel@tonic-gate  *	Emulex MD21 SCSI/ESDI Controller
797c478bd9Sstevel@tonic-gate  *	Emulex MT02 SCSI/QIC-36 Controller.
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  * 1) The Emulex controllers put error class and error code into the byte
827c478bd9Sstevel@tonic-gate  * right after the 'additional sense length' field in Extended Sense.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * 2) Except that some people state that this isn't so for the MD21- only
857c478bd9Sstevel@tonic-gate  * the MT02.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	emulex_ercl_ercd	es_cmd_info[0]
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * 2) These are valid on Extended Sense for the MD21, FORMAT command only:
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #define	emulex_cyl_msb		es_info_1
957c478bd9Sstevel@tonic-gate #define	emulex_cyl_lsb		es_info_2
967c478bd9Sstevel@tonic-gate #define	emulex_head_num		es_info_3
977c478bd9Sstevel@tonic-gate #define	emulex_sect_num		es_info_4
987c478bd9Sstevel@tonic-gate 
995c46c6a0Spd144616 struct scsi_descr_template {
1005c46c6a0Spd144616 	uchar_t sdt_descr_type;
1015c46c6a0Spd144616 	uchar_t sdt_addl_length;
1025c46c6a0Spd144616 };
1035c46c6a0Spd144616 
1045c46c6a0Spd144616 /*
1055c46c6a0Spd144616  * Function prototypes for descriptor-format sense data functions
1065c46c6a0Spd144616  */
1075c46c6a0Spd144616 
1085c46c6a0Spd144616 uint8_t *scsi_find_sense_descr(uint8_t *sense_buffer, int sense_buf_len,
1095c46c6a0Spd144616     int descr_type);
1105c46c6a0Spd144616 
1115c46c6a0Spd144616 /*
1125c46c6a0Spd144616  * Function prototypes for format-neutral sense data functions
1135c46c6a0Spd144616  */
1145c46c6a0Spd144616 
1155c46c6a0Spd144616 uint8_t scsi_sense_key(uint8_t *sense_buffer);
1165c46c6a0Spd144616 
1175c46c6a0Spd144616 uint8_t scsi_sense_asc(uint8_t *sense_buffer);
1185c46c6a0Spd144616 
1195c46c6a0Spd144616 uint8_t scsi_sense_ascq(uint8_t *sense_buffer);
1205c46c6a0Spd144616 
1215c46c6a0Spd144616 boolean_t scsi_sense_info_uint64(uint8_t *sense_buffer,
1225c46c6a0Spd144616     int sense_buf_len, uint64_t *information);
1235c46c6a0Spd144616 
1245c46c6a0Spd144616 boolean_t scsi_sense_cmdspecific_uint64(uint8_t *sense_buffer,
1255c46c6a0Spd144616     int sense_buf_len, uint64_t *cmd_spec_info);
1265c46c6a0Spd144616 
1275c46c6a0Spd144616 void scsi_ext_sense_fields(uint8_t *sense_buffer, int sense_buf_len,
1285c46c6a0Spd144616     uint8_t **information, uint8_t **cmd_spec_info, uint8_t **fru_code,
1295c46c6a0Spd144616     uint8_t **sk_specific, uint8_t **stream_flags);
1305c46c6a0Spd144616 
1315c46c6a0Spd144616 int scsi_validate_sense(uint8_t *sense_buffer, int sense_buf_len, int *flags);
1325c46c6a0Spd144616 
1335c46c6a0Spd144616 /*
1345c46c6a0Spd144616  * Return codes for scsi_validate_sense
1355c46c6a0Spd144616  */
1365c46c6a0Spd144616 
1375c46c6a0Spd144616 #define	SENSE_UNUSABLE		0
1385c46c6a0Spd144616 #define	SENSE_FIXED_FORMAT	1
1395c46c6a0Spd144616 #define	SENSE_DESCR_FORMAT	2
1405c46c6a0Spd144616 
1415c46c6a0Spd144616 /*
1425c46c6a0Spd144616  * Flags from scsi_validate_sense
1435c46c6a0Spd144616  */
1445c46c6a0Spd144616 
1455c46c6a0Spd144616 #define	SNS_BUF_OVERFLOW	1	/* Sense buffer too small */
1465c46c6a0Spd144616 #define	SNS_BUF_DEFERRED 	2 	/* Sense data is for prior operation */
1475c46c6a0Spd144616 
1487c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_IMPL_SENSE_H */
153