4 /* Feel free to copy and modify this GPL-ed code into your applications. */
6 /* Version 0.90 (20030519)
10 /* Some of the following error/status codes are exchanged between the
11 various layers of the SCSI sub-system in Linux and should never
12 reach the user. They are placed here for completeness. What appears
13 here is copied from drivers/scsi/scsi.h which is not visible in
16 #ifndef SCSI_CHECK_CONDITION
17 /* Following are the "true" SCSI status codes. Linux has traditionally
18 used a 1 bit right and masked version of these. So now CHECK_CONDITION
19 and friends (in <scsi/scsi.h>) are deprecated. */
20 #define SCSI_CHECK_CONDITION 0x2
21 #define SCSI_CONDITION_MET 0x4
23 #define SCSI_IMMEDIATE 0x10
24 #define SCSI_IMMEDIATE_CONDITION_MET 0x14
25 #define SCSI_RESERVATION_CONFLICT 0x18
26 #define SCSI_COMMAND_TERMINATED 0x22
27 #define SCSI_TASK_SET_FULL 0x28
28 #define SCSI_ACA_ACTIVE 0x30
29 #define SCSI_TASK_ABORTED 0x40
32 /* The following are 'host_status' codes */
36 #ifndef DID_NO_CONNECT
37 #define DID_NO_CONNECT 0x01 /* Unable to connect before timeout */
38 #define DID_BUS_BUSY 0x02 /* Bus remain busy until timeout */
39 #define DID_TIME_OUT 0x03 /* Timed out for some other reason */
40 #define DID_BAD_TARGET 0x04 /* Bad target (id?) */
41 #define DID_ABORT 0x05 /* Told to abort for some other reason */
42 #define DID_PARITY 0x06 /* Parity error (on SCSI bus) */
43 #define DID_ERROR 0x07 /* Internal error */
44 #define DID_RESET 0x08 /* Reset by somebody */
45 #define DID_BAD_INTR 0x09 /* Received an unexpected interrupt */
46 #define DID_PASSTHROUGH 0x0a /* Force command past mid-level */
47 #define DID_SOFT_ERROR 0x0b /* The low-level driver wants a retry */
50 /* These defines are to isolate applictaions from kernel define changes */
51 #define SG_ERR_DID_OK DID_OK
52 #define SG_ERR_DID_NO_CONNECT DID_NO_CONNECT
53 #define SG_ERR_DID_BUS_BUSY DID_BUS_BUSY
54 #define SG_ERR_DID_TIME_OUT DID_TIME_OUT
55 #define SG_ERR_DID_BAD_TARGET DID_BAD_TARGET
56 #define SG_ERR_DID_ABORT DID_ABORT
57 #define SG_ERR_DID_PARITY DID_PARITY
58 #define SG_ERR_DID_ERROR DID_ERROR
59 #define SG_ERR_DID_RESET DID_RESET
60 #define SG_ERR_DID_BAD_INTR DID_BAD_INTR
61 #define SG_ERR_DID_PASSTHROUGH DID_PASSTHROUGH
62 #define SG_ERR_DID_SOFT_ERROR DID_SOFT_ERROR
64 /* The following are 'driver_status' codes */
66 #define DRIVER_OK 0x00
69 #define DRIVER_BUSY 0x01
70 #define DRIVER_SOFT 0x02
71 #define DRIVER_MEDIA 0x03
72 #define DRIVER_ERROR 0x04
73 #define DRIVER_INVALID 0x05
74 #define DRIVER_TIMEOUT 0x06
75 #define DRIVER_HARD 0x07
76 #define DRIVER_SENSE 0x08 /* Sense_buffer has been set */
78 /* Following "suggests" are "or-ed" with one of previous 8 entries */
79 #define SUGGEST_RETRY 0x10
80 #define SUGGEST_ABORT 0x20
81 #define SUGGEST_REMAP 0x30
82 #define SUGGEST_DIE 0x40
83 #define SUGGEST_SENSE 0x80
84 #define SUGGEST_IS_OK 0xff
87 #define DRIVER_MASK 0x0f
90 #define SUGGEST_MASK 0xf0
93 /* These defines are to isolate applictaions from kernel define changes */
94 #define SG_ERR_DRIVER_OK DRIVER_OK
95 #define SG_ERR_DRIVER_BUSY DRIVER_BUSY
96 #define SG_ERR_DRIVER_SOFT DRIVER_SOFT
97 #define SG_ERR_DRIVER_MEDIA DRIVER_MEDIA
98 #define SG_ERR_DRIVER_ERROR DRIVER_ERROR
99 #define SG_ERR_DRIVER_INVALID DRIVER_INVALID
100 #define SG_ERR_DRIVER_TIMEOUT DRIVER_TIMEOUT
101 #define SG_ERR_DRIVER_HARD DRIVER_HARD
102 #define SG_ERR_DRIVER_SENSE DRIVER_SENSE
103 #define SG_ERR_SUGGEST_RETRY SUGGEST_RETRY
104 #define SG_ERR_SUGGEST_ABORT SUGGEST_ABORT
105 #define SG_ERR_SUGGEST_REMAP SUGGEST_REMAP
106 #define SG_ERR_SUGGEST_DIE SUGGEST_DIE
107 #define SG_ERR_SUGGEST_SENSE SUGGEST_SENSE
108 #define SG_ERR_SUGGEST_IS_OK SUGGEST_IS_OK
109 #define SG_ERR_DRIVER_MASK DRIVER_MASK
110 #define SG_ERR_SUGGEST_MASK SUGGEST_MASK
114 /* The following "print" functions send ACSII to stdout */
115 extern void sg_print_command(const unsigned char * command);
116 extern void sg_print_sense(const char * leadin,
117 const unsigned char * sense_buffer, int sb_len);
118 extern void sg_print_status(int masked_status);
119 extern void sg_print_scsi_status(int scsi_status);
120 extern void sg_print_host_status(int host_status);
121 extern void sg_print_driver_status(int driver_status);
123 /* sg_chk_n_print() returns 1 quietly if there are no errors/warnings
124 else it prints to standard output and returns 0. */
125 extern int sg_chk_n_print(const char * leadin, int masked_status,
126 int host_status, int driver_status,
127 const unsigned char * sense_buffer, int sb_len);
129 /* The following function declaration is for the sg version 3 driver.
130 Only version 3 sg_err.c defines it. */
132 extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp);
135 /* The following "category" function returns one of the following */
136 #define SG_ERR_CAT_CLEAN 0 /* No errors or other information */
137 #define SG_ERR_CAT_MEDIA_CHANGED 1 /* interpreted from sense buffer */
138 #define SG_ERR_CAT_RESET 2 /* interpreted from sense buffer */
139 #define SG_ERR_CAT_TIMEOUT 3
140 #define SG_ERR_CAT_RECOVERED 4 /* Successful command after recovered err */
141 #define SG_ERR_CAT_SENSE 98 /* Something else is in the sense buffer */
142 #define SG_ERR_CAT_OTHER 99 /* Some other error/warning has occurred */
144 extern int sg_err_category(int masked_status, int host_status,
145 int driver_status, const unsigned char * sense_buffer,
148 extern int sg_err_category_new(int scsi_status, int host_status,
149 int driver_status, const unsigned char * sense_buffer,
152 /* The following function declaration is for the sg version 3 driver.
153 Only version 3 sg_err.c defines it. */
154 extern int sg_err_category3(struct sg_io_hdr * hp);
156 /* Returns length of SCSI command given the opcode (first byte) */
157 extern int sg_get_command_size(unsigned char opcode);
159 extern void sg_get_command_name(unsigned char opcode, int buff_len,