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