^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Largely written by Julian Elischer (julian@tfs.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * for TRW Financial Systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * TRW Financial Systems, in accordance with their agreement with Carnegie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Mellon University, makes this software available to CMU to distribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * or use in any manner that they see fit as long as this message is kept with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * the software. For this reason TFS also grants any other persons or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * organisations permission to use or modify this software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * TFS supplies this software to be publicly redistributed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * on the understanding that TFS is not responsible for the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * functioning of this software in any circumstances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.21 2002/10/08 17:12:44 ken Exp $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Copyright (c) 2003 Adaptec Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * notice, this list of conditions, and the following disclaimer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * without modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * 2. Redistributions in binary form must reproduce at minimum a disclaimer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * substantially similar to the "NO WARRANTY" disclaimer below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * ("Disclaimer") and any redistribution must be conditioned upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * including a substantially similar Disclaimer requirement for further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * binary redistribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * 3. Neither the names of the above-listed copyright holders nor the names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * of any contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Alternatively, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * GNU General Public License ("GPL") version 2 as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * NO WARRANTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * POSSIBILITY OF SUCH DAMAGES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * $Id$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #ifndef _AICLIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define _AICLIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct scsi_sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) uint8_t opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) uint8_t byte2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) uint8_t unused[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) uint8_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) uint8_t control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define SCSI_REV_0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define SCSI_REV_CCS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define SCSI_REV_2 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define SCSI_REV_SPC 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define SCSI_REV_SPC2 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct scsi_sense_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) uint8_t error_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define SSD_ERRCODE 0x7F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define SSD_CURRENT_ERROR 0x70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define SSD_DEFERRED_ERROR 0x71
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SSD_ERRCODE_VALID 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) uint8_t segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) uint8_t flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define SSD_KEY 0x0F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define SSD_KEY_NO_SENSE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define SSD_KEY_RECOVERED_ERROR 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define SSD_KEY_NOT_READY 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define SSD_KEY_MEDIUM_ERROR 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define SSD_KEY_HARDWARE_ERROR 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define SSD_KEY_ILLEGAL_REQUEST 0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define SSD_KEY_UNIT_ATTENTION 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define SSD_KEY_DATA_PROTECT 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define SSD_KEY_BLANK_CHECK 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define SSD_KEY_Vendor_Specific 0x09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define SSD_KEY_COPY_ABORTED 0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define SSD_KEY_ABORTED_COMMAND 0x0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define SSD_KEY_EQUAL 0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define SSD_KEY_VOLUME_OVERFLOW 0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define SSD_KEY_MISCOMPARE 0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define SSD_KEY_RESERVED 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define SSD_ILI 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define SSD_EOM 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define SSD_FILEMARK 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) uint8_t info[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) uint8_t extra_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) uint8_t cmd_spec_info[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) uint8_t add_sense_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) uint8_t add_sense_code_qual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) uint8_t fru;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) uint8_t sense_key_spec[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define SSD_SCS_VALID 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define SSD_FIELDPTR_CMD 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define SSD_BITPTR_VALID 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define SSD_BITPTR_VALUE 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define SSD_MIN_SIZE 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) uint8_t extra_bytes[14];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Status Byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define SCSI_STATUS_OK 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define SCSI_STATUS_CHECK_COND 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define SCSI_STATUS_COND_MET 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define SCSI_STATUS_BUSY 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define SCSI_STATUS_INTERMED 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define SCSI_STATUS_INTERMED_COND_MET 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define SCSI_STATUS_RESERV_CONFLICT 0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define SCSI_STATUS_QUEUE_FULL 0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define SCSI_STATUS_ACA_ACTIVE 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define SCSI_STATUS_TASK_ABORTED 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /************************* Large Disk Handling ********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) aic_sector_div(sector_t capacity, int heads, int sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* ugly, ugly sector_div calling convention.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sector_div(capacity, (heads * sectors));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return (int)capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static inline uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) scsi_4btoul(uint8_t *bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) uint32_t rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) rv = (bytes[0] << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) (bytes[1] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) (bytes[2] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) bytes[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return (rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Macros for generating the elements of the PCI ID tables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define ID_C(x, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (c) << 8, 0xFFFF00, 0 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define ID2C(x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ID_C(x, PCI_CLASS_STORAGE_SCSI), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ID_C(x, PCI_CLASS_STORAGE_RAID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Generate IDs for all 16 possibilites.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * The argument has already masked out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * the 4 least significant bits of the device id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * (e.g., mask: ID_9005_GENERIC_MASK).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define ID16(x) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ID(x), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ID((x) | 0x0001000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ID((x) | 0x0002000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ID((x) | 0x0003000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ID((x) | 0x0004000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ID((x) | 0x0005000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ID((x) | 0x0006000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ID((x) | 0x0007000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ID((x) | 0x0008000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ID((x) | 0x0009000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ID((x) | 0x000A000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ID((x) | 0x000B000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ID((x) | 0x000C000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ID((x) | 0x000D000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ID((x) | 0x000E000000000000ull), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ID((x) | 0x000F000000000000ull)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #endif /*_AICLIB_H */