1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 * MA 02111-1307 USA
16 */
17#ifndef SG_IO_LINUX_H
18#define SG_IO_LINUX_H
19
20/*
21 * Copyright (c) 2004-2005 Douglas Gilbert.
22 * All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 *    notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 *    notice, this list of conditions and the following disclaimer in the
31 *    documentation and/or other materials provided with the distribution.
32 * 3. The name of the author may not be used to endorse or promote products
33 *    derived from this software without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 */
48
49/*
50 * Version 1.02 [20070121]
51 */
52
53/*
54 * This header file contains linux specific information related to the SCSI
55 * command pass through in the SCSI generic (sg) driver and the linux
56 * block layer.
57 */
58
59#include "sg_lib.h"
60#include "sg_linux_inc.h"
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* The following are 'host_status' codes */
67#ifndef DID_OK
68#define DID_OK 0x00
69#endif
70#ifndef DID_NO_CONNECT
71#define DID_NO_CONNECT 0x01     /* Unable to connect before timeout */
72#define DID_BUS_BUSY 0x02       /* Bus remain busy until timeout */
73#define DID_TIME_OUT 0x03       /* Timed out for some other reason */
74#define DID_BAD_TARGET 0x04     /* Bad target (id?) */
75#define DID_ABORT 0x05          /* Told to abort for some other reason */
76#define DID_PARITY 0x06         /* Parity error (on SCSI bus) */
77#define DID_ERROR 0x07          /* Internal error */
78#define DID_RESET 0x08          /* Reset by somebody */
79#define DID_BAD_INTR 0x09       /* Received an unexpected interrupt */
80#define DID_PASSTHROUGH 0x0a    /* Force command past mid-level */
81#define DID_SOFT_ERROR 0x0b     /* The low-level driver wants a retry */
82#endif
83#ifndef DID_IMM_RETRY
84#define DID_IMM_RETRY 0x0c      /* Retry without decrementing retry count  */
85#endif
86#ifndef DID_REQUEUE
87#define DID_REQUEUE 0x0d        /* Requeue command (no immediate retry) also
88                                 * without decrementing the retry count    */
89#endif
90
91/* These defines are to isolate applications from kernel define changes */
92#define SG_LIB_DID_OK           DID_OK
93#define SG_LIB_DID_NO_CONNECT   DID_NO_CONNECT
94#define SG_LIB_DID_BUS_BUSY     DID_BUS_BUSY
95#define SG_LIB_DID_TIME_OUT     DID_TIME_OUT
96#define SG_LIB_DID_BAD_TARGET   DID_BAD_TARGET
97#define SG_LIB_DID_ABORT        DID_ABORT
98#define SG_LIB_DID_PARITY       DID_PARITY
99#define SG_LIB_DID_ERROR        DID_ERROR
100#define SG_LIB_DID_RESET        DID_RESET
101#define SG_LIB_DID_BAD_INTR     DID_BAD_INTR
102#define SG_LIB_DID_PASSTHROUGH  DID_PASSTHROUGH
103#define SG_LIB_DID_SOFT_ERROR   DID_SOFT_ERROR
104#define SG_LIB_DID_IMM_RETRY    DID_IMM_RETRY
105#define SG_LIB_DID_REQUEUE      DID_REQUEUE
106
107/* The following are 'driver_status' codes */
108#ifndef DRIVER_OK
109#define DRIVER_OK 0x00
110#endif
111#ifndef DRIVER_BUSY
112#define DRIVER_BUSY 0x01
113#define DRIVER_SOFT 0x02
114#define DRIVER_MEDIA 0x03
115#define DRIVER_ERROR 0x04
116#define DRIVER_INVALID 0x05
117#define DRIVER_TIMEOUT 0x06
118#define DRIVER_HARD 0x07
119#define DRIVER_SENSE 0x08       /* Sense_buffer has been set */
120
121/* Following "suggests" are "or-ed" with one of previous 8 entries */
122#define SUGGEST_RETRY 0x10
123#define SUGGEST_ABORT 0x20
124#define SUGGEST_REMAP 0x30
125#define SUGGEST_DIE 0x40
126#define SUGGEST_SENSE 0x80
127#define SUGGEST_IS_OK 0xff
128#endif
129#ifndef DRIVER_MASK
130#define DRIVER_MASK 0x0f
131#endif
132#ifndef SUGGEST_MASK
133#define SUGGEST_MASK 0xf0
134#endif
135
136/* These defines are to isolate applications from kernel define changes */
137#define SG_LIB_DRIVER_OK        DRIVER_OK
138#define SG_LIB_DRIVER_BUSY      DRIVER_BUSY
139#define SG_LIB_DRIVER_SOFT      DRIVER_SOFT
140#define SG_LIB_DRIVER_MEDIA     DRIVER_MEDIA
141#define SG_LIB_DRIVER_ERROR     DRIVER_ERROR
142#define SG_LIB_DRIVER_INVALID   DRIVER_INVALID
143#define SG_LIB_DRIVER_TIMEOUT   DRIVER_TIMEOUT
144#define SG_LIB_DRIVER_HARD      DRIVER_HARD
145#define SG_LIB_DRIVER_SENSE     DRIVER_SENSE
146#define SG_LIB_SUGGEST_RETRY    SUGGEST_RETRY
147#define SG_LIB_SUGGEST_ABORT    SUGGEST_ABORT
148#define SG_LIB_SUGGEST_REMAP    SUGGEST_REMAP
149#define SG_LIB_SUGGEST_DIE      SUGGEST_DIE
150#define SG_LIB_SUGGEST_SENSE    SUGGEST_SENSE
151#define SG_LIB_SUGGEST_IS_OK    SUGGEST_IS_OK
152#define SG_LIB_DRIVER_MASK      DRIVER_MASK
153#define SG_LIB_SUGGEST_MASK     SUGGEST_MASK
154
155extern void sg_print_masked_status(int masked_status);
156extern void sg_print_host_status(int host_status);
157extern void sg_print_driver_status(int driver_status);
158
159/* sg_chk_n_print() returns 1 quietly if there are no errors/warnings
160   else it prints errors/warnings (prefixed by 'leadin') to
161   'sg_warnings_fd' and returns 0. */
162extern int sg_chk_n_print(const char * leadin, int masked_status,
163                          int host_status, int driver_status,
164                          const unsigned char * sense_buffer, int sb_len,
165                          int raw_sinfo);
166
167/* The following function declaration is for the sg version 3 driver. */
168struct sg_io_hdr;
169/* sg_chk_n_print3() returns 1 quietly if there are no errors/warnings;
170   else it prints errors/warnings (prefixed by 'leadin') to
171   'sg_warnings_fd' and returns 0. */
172extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp,
173                           int raw_sinfo);
174
175/* Calls sg_scsi_normalize_sense() after obtaining the sense buffer and
176   its length from the struct sg_io_hdr pointer. If these cannot be
177   obtained, 0 is returned. */
178extern int sg_normalize_sense(const struct sg_io_hdr * hp,
179                              struct sg_scsi_sense_hdr * sshp);
180
181extern int sg_err_category(int masked_status, int host_status,
182               int driver_status, const unsigned char * sense_buffer,
183               int sb_len);
184
185extern int sg_err_category_new(int scsi_status, int host_status,
186               int driver_status, const unsigned char * sense_buffer,
187               int sb_len);
188
189/* The following function declaration is for the sg version 3 driver. */
190extern int sg_err_category3(struct sg_io_hdr * hp);
191
192
193/* Note about SCSI status codes found in older versions of Linux.
194   Linux has traditionally used a 1 bit right shifted and masked
195   version of SCSI standard status codes. Now CHECK_CONDITION
196   and friends (in <scsi/scsi.h>) are deprecated. */
197
198#ifdef __cplusplus
199}
200#endif
201
202#endif
203