4 /* Feel free to copy and modify this GPL-ed code into your applications. */
6 /* Version 0.84 (20010115)
7 - all output now sent to stderr rather thatn stdout
8 - remove header files included in this file
12 /* Some of the following error/status codes are exchanged between the
13 various layers of the SCSI sub-system in Linux and should never
14 reach the user. They are placed here for completeness. What appears
15 here is copied from drivers/scsi/scsi.h which is not visible in
18 /* The following are 'host_status' codes */
22 #ifndef DID_NO_CONNECT
23 #define DID_NO_CONNECT 0x01 /* Unable to connect before timeout */
24 #define DID_BUS_BUSY 0x02 /* Bus remain busy until timeout */
25 #define DID_TIME_OUT 0x03 /* Timed out for some other reason */
26 #define DID_BAD_TARGET 0x04 /* Bad target (id?) */
27 #define DID_ABORT 0x05 /* Told to abort for some other reason */
28 #define DID_PARITY 0x06 /* Parity error (on SCSI bus) */
29 #define DID_ERROR 0x07 /* Internal error */
30 #define DID_RESET 0x08 /* Reset by somebody */
31 #define DID_BAD_INTR 0x09 /* Received an unexpected interrupt */
32 #define DID_PASSTHROUGH 0x0a /* Force command past mid-level */
33 #define DID_SOFT_ERROR 0x0b /* The low-level driver wants a retry */
36 /* These defines are to isolate applictaions from kernel define changes */
37 #define SG_ERR_DID_OK DID_OK
38 #define SG_ERR_DID_NO_CONNECT DID_NO_CONNECT
39 #define SG_ERR_DID_BUS_BUSY DID_BUS_BUSY
40 #define SG_ERR_DID_TIME_OUT DID_TIME_OUT
41 #define SG_ERR_DID_BAD_TARGET DID_BAD_TARGET
42 #define SG_ERR_DID_ABORT DID_ABORT
43 #define SG_ERR_DID_PARITY DID_PARITY
44 #define SG_ERR_DID_ERROR DID_ERROR
45 #define SG_ERR_DID_RESET DID_RESET
46 #define SG_ERR_DID_BAD_INTR DID_BAD_INTR
47 #define SG_ERR_DID_PASSTHROUGH DID_PASSTHROUGH
48 #define SG_ERR_DID_SOFT_ERROR DID_SOFT_ERROR
50 /* The following are 'driver_status' codes */
52 #define DRIVER_OK 0x00
55 #define DRIVER_BUSY 0x01
56 #define DRIVER_SOFT 0x02
57 #define DRIVER_MEDIA 0x03
58 #define DRIVER_ERROR 0x04
59 #define DRIVER_INVALID 0x05
60 #define DRIVER_TIMEOUT 0x06
61 #define DRIVER_HARD 0x07
62 #define DRIVER_SENSE 0x08 /* Sense_buffer has been set */
64 /* Following "suggests" are "or-ed" with one of previous 8 entries */
65 #define SUGGEST_RETRY 0x10
66 #define SUGGEST_ABORT 0x20
67 #define SUGGEST_REMAP 0x30
68 #define SUGGEST_DIE 0x40
69 #define SUGGEST_SENSE 0x80
70 #define SUGGEST_IS_OK 0xff
73 #define DRIVER_MASK 0x0f
76 #define SUGGEST_MASK 0xf0
79 /* These defines are to isolate applictaions from kernel define changes */
80 #define SG_ERR_DRIVER_OK DRIVER_OK
81 #define SG_ERR_DRIVER_BUSY DRIVER_BUSY
82 #define SG_ERR_DRIVER_SOFT DRIVER_SOFT
83 #define SG_ERR_DRIVER_MEDIA DRIVER_MEDIA
84 #define SG_ERR_DRIVER_ERROR DRIVER_ERROR
85 #define SG_ERR_DRIVER_INVALID DRIVER_INVALID
86 #define SG_ERR_DRIVER_TIMEOUT DRIVER_TIMEOUT
87 #define SG_ERR_DRIVER_HARD DRIVER_HARD
88 #define SG_ERR_DRIVER_SENSE DRIVER_SENSE
89 #define SG_ERR_SUGGEST_RETRY SUGGEST_RETRY
90 #define SG_ERR_SUGGEST_ABORT SUGGEST_ABORT
91 #define SG_ERR_SUGGEST_REMAP SUGGEST_REMAP
92 #define SG_ERR_SUGGEST_DIE SUGGEST_DIE
93 #define SG_ERR_SUGGEST_SENSE SUGGEST_SENSE
94 #define SG_ERR_SUGGEST_IS_OK SUGGEST_IS_OK
95 #define SG_ERR_DRIVER_MASK DRIVER_MASK
96 #define SG_ERR_SUGGEST_MASK SUGGEST_MASK
100 /* The following "print" functions send ACSII to stdout */
101 extern void sg_print_command(const unsigned char * command);
102 extern void sg_print_sense(const char * leadin,
103 const unsigned char * sense_buffer, int sb_len);
104 extern void sg_print_status(int masked_status);
105 extern void sg_print_host_status(int host_status);
106 extern void sg_print_driver_status(int driver_status);
108 /* sg_chk_n_print() returns 1 quietly if there are no errors/warnings
109 else it prints to standard output and returns 0. */
110 extern int sg_chk_n_print(const char * leadin, int masked_status,
111 int host_status, int driver_status,
112 const unsigned char * sense_buffer, int sb_len);
114 /* The following function declaration is for the sg version 3 driver.
115 Only version 3 sg_err.c defines it. */
117 extern int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp);
120 /* The following "category" function returns one of the following */
121 #define SG_ERR_CAT_CLEAN 0 /* No errors or other information */
122 #define SG_ERR_CAT_MEDIA_CHANGED 1 /* interpreted from sense buffer */
123 #define SG_ERR_CAT_RESET 2 /* interpreted from sense buffer */
124 #define SG_ERR_CAT_TIMEOUT 3
125 #define SG_ERR_CAT_RECOVERED 4 /* Successful command after recovered err */
126 #define SG_ERR_CAT_SENSE 98 /* Something else is in the sense buffer */
127 #define SG_ERR_CAT_OTHER 99 /* Some other error/warning has occurred */
129 extern int sg_err_category(int masked_status, int host_status,
130 int driver_status, const unsigned char * sense_buffer,
133 /* The following function declaration is for the sg version 3 driver.
134 Only version 3 sg_err.c defines it. */
135 extern int sg_err_category3(struct sg_io_hdr * hp);
137 /* Returns length of SCSI command given the opcode (first byte) */
138 int sg_get_command_size(unsigned char opcode);