1 #ifndef SG_IO_LINUX_H 2 #define SG_IO_LINUX_H 3 4 /* 5 * Copyright (c) 2004-2020 Douglas Gilbert. 6 * All rights reserved. 7 * Use of this source code is governed by a BSD-style 8 * license that can be found in the BSD_LICENSE file. 9 * 10 * SPDX-License-Identifier: BSD-2-Clause 11 */ 12 13 /* 14 * Version 1.08 [20201102] 15 */ 16 17 /* 18 * This header file contains Linux specific information related to the SCSI 19 * command pass through in the SCSI generic (sg) driver and the Linux 20 * block layer. 21 */ 22 23 #include "sg_lib.h" 24 #include "sg_linux_inc.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* host_bytes: DID_* are Linux SCSI result (a 32 bit variable) bits 16:23 */ 31 #ifndef DID_OK 32 #define DID_OK 0x00 33 #endif 34 #ifndef DID_NO_CONNECT 35 #define DID_NO_CONNECT 0x01 /* Unable to connect before timeout */ 36 #define DID_BUS_BUSY 0x02 /* Bus remain busy until timeout */ 37 #define DID_TIME_OUT 0x03 /* Timed out for some other reason */ 38 #define DID_BAD_TARGET 0x04 /* Bad target (id?) */ 39 #define DID_ABORT 0x05 /* Told to abort for some other reason */ 40 #define DID_PARITY 0x06 /* Parity error (on SCSI bus) */ 41 #define DID_ERROR 0x07 /* Internal error */ 42 #define DID_RESET 0x08 /* Reset by somebody */ 43 #define DID_BAD_INTR 0x09 /* Received an unexpected interrupt */ 44 #define DID_PASSTHROUGH 0x0a /* Force command past mid-level */ 45 #define DID_SOFT_ERROR 0x0b /* The low-level driver wants a retry */ 46 #endif 47 #ifndef DID_IMM_RETRY 48 #define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ 49 #endif 50 #ifndef DID_REQUEUE 51 #define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also 52 * without decrementing the retry count */ 53 #endif 54 #ifndef DID_TRANSPORT_DISRUPTED 55 #define DID_TRANSPORT_DISRUPTED 0xe 56 #endif 57 #ifndef DID_TRANSPORT_FAILFAST 58 #define DID_TRANSPORT_FAILFAST 0xf 59 #endif 60 #ifndef DID_TARGET_FAILURE 61 #define DID_TARGET_FAILURE 0x10 62 #endif 63 #ifndef DID_NEXUS_FAILURE 64 #define DID_NEXUS_FAILURE 0x11 65 #endif 66 67 /* These defines are to isolate applications from kernel define changes */ 68 #define SG_LIB_DID_OK DID_OK 69 #define SG_LIB_DID_NO_CONNECT DID_NO_CONNECT 70 #define SG_LIB_DID_BUS_BUSY DID_BUS_BUSY 71 #define SG_LIB_DID_TIME_OUT DID_TIME_OUT 72 #define SG_LIB_DID_BAD_TARGET DID_BAD_TARGET 73 #define SG_LIB_DID_ABORT DID_ABORT 74 #define SG_LIB_DID_PARITY DID_PARITY 75 #define SG_LIB_DID_ERROR DID_ERROR 76 #define SG_LIB_DID_RESET DID_RESET 77 #define SG_LIB_DID_BAD_INTR DID_BAD_INTR 78 #define SG_LIB_DID_PASSTHROUGH DID_PASSTHROUGH 79 #define SG_LIB_DID_SOFT_ERROR DID_SOFT_ERROR 80 #define SG_LIB_DID_IMM_RETRY DID_IMM_RETRY 81 #define SG_LIB_DID_REQUEUE DID_REQUEUE 82 #define SG_LIB_TRANSPORT_DISRUPTED DID_TRANSPORT_DISRUPTED 83 #define SG_LIB_DID_TRANSPORT_FAILFAST DID_TRANSPORT_FAILFAST 84 #define SG_LIB_DID_TARGET_FAILURE DID_TARGET_FAILURE 85 #define SG_LIB_DID_NEXUS_FAILURE DID_NEXUS_FAILURE 86 87 /* DRIVER_* are Linux SCSI result (a 32 bit variable) bits 24:27 */ 88 #ifndef DRIVER_OK 89 #define DRIVER_OK 0x00 90 #endif 91 #ifndef DRIVER_BUSY 92 #define DRIVER_BUSY 0x01 93 #define DRIVER_SOFT 0x02 94 #define DRIVER_MEDIA 0x03 95 #define DRIVER_ERROR 0x04 96 #define DRIVER_INVALID 0x05 97 #define DRIVER_TIMEOUT 0x06 98 #define DRIVER_HARD 0x07 99 #define DRIVER_SENSE 0x08 /* Sense_buffer has been set */ 100 101 /* SUGGEST_* are Linux SCSI result (a 32 bit variable) bits 28:31 */ 102 /* N.B. the SUGGEST_* codes are no longer used in Linux and are only kept 103 * to stop compilation breakages. 104 * Following "suggests" are "or-ed" with one of previous 8 entries */ 105 #define SUGGEST_RETRY 0x10 106 #define SUGGEST_ABORT 0x20 107 #define SUGGEST_REMAP 0x30 108 #define SUGGEST_DIE 0x40 109 #define SUGGEST_SENSE 0x80 110 #define SUGGEST_IS_OK 0xff 111 #endif 112 113 #ifndef DRIVER_MASK 114 #define DRIVER_MASK 0x0f 115 #endif 116 #ifndef SUGGEST_MASK 117 #define SUGGEST_MASK 0xf0 118 #endif 119 120 /* These defines are to isolate applications from kernel define changes */ 121 #define SG_LIB_DRIVER_OK DRIVER_OK 122 #define SG_LIB_DRIVER_BUSY DRIVER_BUSY 123 #define SG_LIB_DRIVER_SOFT DRIVER_SOFT 124 #define SG_LIB_DRIVER_MEDIA DRIVER_MEDIA 125 #define SG_LIB_DRIVER_ERROR DRIVER_ERROR 126 #define SG_LIB_DRIVER_INVALID DRIVER_INVALID 127 #define SG_LIB_DRIVER_TIMEOUT DRIVER_TIMEOUT 128 #define SG_LIB_DRIVER_HARD DRIVER_HARD 129 #define SG_LIB_DRIVER_SENSE DRIVER_SENSE 130 131 132 /* N.B. the SUGGEST_* codes are no longer used in Linux and are only kept 133 * to stop compilation breakages. */ 134 #define SG_LIB_SUGGEST_RETRY SUGGEST_RETRY 135 #define SG_LIB_SUGGEST_ABORT SUGGEST_ABORT 136 #define SG_LIB_SUGGEST_REMAP SUGGEST_REMAP 137 #define SG_LIB_SUGGEST_DIE SUGGEST_DIE 138 #define SG_LIB_SUGGEST_SENSE SUGGEST_SENSE 139 #define SG_LIB_SUGGEST_IS_OK SUGGEST_IS_OK 140 #define SG_LIB_DRIVER_MASK DRIVER_MASK 141 #define SG_LIB_SUGGEST_MASK SUGGEST_MASK 142 143 void sg_print_masked_status(int masked_status); 144 void sg_print_host_status(int host_status); 145 void sg_print_driver_status(int driver_status); 146 147 /* sg_chk_n_print() returns 1 quietly if there are no errors/warnings 148 * else it prints errors/warnings (prefixed by 'leadin') to 149 * 'sg_warnings_fd' and returns 0. raw_sinfo indicates whether the 150 * raw sense buffer (in ASCII hex) should be printed. */ 151 int sg_chk_n_print(const char * leadin, int masked_status, int host_status, 152 int driver_status, const uint8_t * sense_buffer, 153 int sb_len, bool raw_sinfo); 154 155 /* The following function declaration is for the sg version 3 driver. */ 156 struct sg_io_hdr; 157 158 /* sg_chk_n_print3() returns 1 quietly if there are no errors/warnings; 159 * else it prints errors/warnings (prefixed by 'leadin') to 160 * 'sg_warnings_fd' and returns 0. For sg_io_v4 interface use 161 * sg_linux_sense_print() instead. */ 162 int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp, 163 bool raw_sinfo); 164 165 /* Returns 1 if no errors found and thus nothing printed; otherwise 166 * prints error/warning (prefix by 'leadin') to stderr (pr2ws) and 167 * returns 0. */ 168 int sg_linux_sense_print(const char * leadin, int scsi_status, 169 int host_status, int driver_status, 170 const uint8_t * sense_buffer, int sb_len, 171 bool raw_sinfo); 172 173 /* Calls sg_scsi_normalize_sense() after obtaining the sense buffer and 174 * its length from the struct sg_io_hdr pointer. If these cannot be 175 * obtained, false is returned. For sg_io_v4 interface use 176 * sg_scsi_normalize_sense() function instead [see sg_lib.h]. */ 177 bool sg_normalize_sense(const struct sg_io_hdr * hp, 178 struct sg_scsi_sense_hdr * sshp); 179 180 /* Returns SG_LIB_CAT_* value. */ 181 int sg_err_category(int masked_status, int host_status, int driver_status, 182 const uint8_t * sense_buffer, int sb_len); 183 184 /* Returns SG_LIB_CAT_* value. */ 185 int sg_err_category_new(int scsi_status, int host_status, int driver_status, 186 const uint8_t * sense_buffer, int sb_len); 187 188 /* The following function declaration is for the sg version 3 driver. for 189 * sg_io_v4 interface use sg_err_category_new() function instead */ 190 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