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