Alexander Martinz | 8ca5ed6 | 2016-11-25 17:06:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Structures and definitions for SCSI commands to the SG passthrough device. |
| 3 | * |
| 4 | * $FreeBSD$ |
| 5 | */ |
| 6 | |
| 7 | #ifndef _SCSI_SG_H |
| 8 | #define _SCSI_SG_H |
| 9 | |
| 10 | #define SGIOC '"' |
| 11 | #define SG_SET_TIMEOUT _IOW(SGIOC, 0x01, u_int) |
| 12 | #define SG_GET_TIMEOUT _IO(SGIOC, 0x02) |
| 13 | #define SG_EMULATED_HOST _IOR(SGIOC, 0x03, int) |
| 14 | #define SG_SET_TRANSFORM _IO(SGIOC, 0x04) |
| 15 | #define SG_GET_TRANSFORM _IO(SGIOC, 0x05) |
| 16 | #define SG_GET_COMMAND_Q _IOW(SGIOC, 0x70, int) |
| 17 | #define SG_SET_COMMAND_Q _IOR(SGIOC, 0x71, int) |
| 18 | #define SG_GET_RESERVED_SIZE _IOR(SGIOC, 0x72, int) |
| 19 | #define SG_SET_RESERVED_SIZE _IOW(SGIOC, 0x75, int) |
| 20 | #define SG_GET_SCSI_ID _IOR(SGIOC, 0x76, struct sg_scsi_id) |
| 21 | #define SG_SET_FORCE_LOW_DMA _IOW(SGIOC, 0x79, int) |
| 22 | #define SG_GET_LOW_DMA _IOR(SGIOC, 0x7a, int) |
| 23 | #define SG_SET_FORCE_PACK_ID _IOW(SGIOC, 0x7b, int) |
| 24 | #define SG_GET_PACK_ID _IOR(SGIOC, 0x7c, int) |
| 25 | #define SG_GET_NUM_WAITING _IOR(SGIOC, 0x7d, int) |
| 26 | #define SG_SET_DEBUG _IOW(SGIOC, 0x7e, int) |
| 27 | #define SG_GET_SG_TABLESIZE _IOR(SGIOC, 0x7f, int) |
| 28 | #define SG_GET_VERSION_NUM _IOR(SGIOC, 0x82, int) |
| 29 | #define SG_NEXT_CMD_LEN _IOW(SGIOC, 0x83, int) |
| 30 | #define SG_SCSI_RESET _IOW(SGIOC, 0x84, int) |
| 31 | #define SG_IO _IOWR(SGIOC, 0x85, struct sg_io_hdr) |
| 32 | #define SG_GET_REQUEST_TABLE _IO(SGIOC, 0x86) |
| 33 | #define SG_SET_KEEP_ORPHAN _IOW(SGIOC, 0x87, int) |
| 34 | #define SG_GET_KEEP_ORPHAN _IOR(SGIOC, 0x88, int) |
| 35 | #define SG_GET_ACCESS_COUNT _IOR(SGIOC, 0x89, int) |
| 36 | |
| 37 | struct sg_io_hdr { |
| 38 | int interface_id; |
| 39 | int dxfer_direction; |
| 40 | u_char cmd_len; |
| 41 | u_char mx_sb_len; |
| 42 | u_short iovec_count; |
| 43 | u_int dxfer_len; |
| 44 | void *dxferp; |
| 45 | u_char *cmdp; |
| 46 | u_char *sbp; |
| 47 | u_int timeout; |
| 48 | u_int flags; |
| 49 | int pack_id; |
| 50 | void *usr_ptr; |
| 51 | u_char status; |
| 52 | u_char masked_status; |
| 53 | u_char msg_status; |
| 54 | u_char sb_len_wr; |
| 55 | u_short host_status; |
| 56 | u_short driver_status; |
| 57 | int resid; |
| 58 | u_int duration; |
| 59 | u_int info; |
| 60 | }; |
| 61 | |
| 62 | struct sg_io_hdr32 { |
| 63 | int interface_id; |
| 64 | int dxfer_direction; |
| 65 | u_char cmd_len; |
| 66 | u_char mx_sb_len; |
| 67 | u_short iovec_count; |
| 68 | u_int dxfer_len; |
| 69 | uint32_t dxferp; |
| 70 | uint32_t cmdp; |
| 71 | uint32_t sbp; |
| 72 | u_int timeout; |
| 73 | u_int flags; |
| 74 | int pack_id; |
| 75 | uint32_t usr_ptr; |
| 76 | u_char status; |
| 77 | u_char masked_status; |
| 78 | u_char msg_status; |
| 79 | u_char sb_len_wr; |
| 80 | u_short host_status; |
| 81 | u_short driver_status; |
| 82 | int resid; |
| 83 | u_int duration; |
| 84 | u_int info; |
| 85 | }; |
| 86 | |
| 87 | typedef struct sg_io_hdr sg_io_hdr_t; |
| 88 | |
| 89 | #define SG_DXFER_NONE -1 |
| 90 | #define SG_DXFER_TO_DEV -2 |
| 91 | #define SG_DXFER_FROM_DEV -3 |
| 92 | #define SG_DXFER_TO_FROM_DEV -4 |
| 93 | #define SG_DXFER_UNKNOWN -5 |
| 94 | |
| 95 | #define SG_MAX_SENSE 16 |
| 96 | struct sg_header { |
| 97 | int pack_len; |
| 98 | int reply_len; |
| 99 | int pack_id; |
| 100 | int result; |
| 101 | u_int twelve_byte:1; |
| 102 | u_int target_status:5; |
| 103 | u_int host_status:8; |
| 104 | u_int driver_status:8; |
| 105 | u_int other_flags:10; |
| 106 | u_char sense_buffer[SG_MAX_SENSE]; |
| 107 | }; |
| 108 | |
| 109 | struct sg_scsi_id { |
| 110 | int host_no; |
| 111 | int channel; |
| 112 | int scsi_id; |
| 113 | int lun; |
| 114 | int scsi_type; |
| 115 | short h_cmd_per_lun; |
| 116 | short d_queue_depth; |
| 117 | int unused[2]; |
| 118 | }; |
| 119 | |
| 120 | struct scsi_idlun { |
| 121 | uint32_t dev_id; |
| 122 | uint32_t host_unique_id; |
| 123 | }; |
| 124 | |
| 125 | /* |
| 126 | * Host codes |
| 127 | */ |
| 128 | #define DID_OK 0x00 /* OK */ |
| 129 | #define DID_NO_CONNECT 0x01 /* timeout during connect */ |
| 130 | #define DID_BUS_BUSY 0x02 /* timeout during command */ |
| 131 | #define DID_TIME_OUT 0x03 /* other timeout */ |
| 132 | #define DID_BAD_TARGET 0x04 /* bad target */ |
| 133 | #define DID_ABORT 0x05 /* abort */ |
| 134 | #define DID_PARITY 0x06 /* parity error */ |
| 135 | #define DID_ERROR 0x07 /* internal error */ |
| 136 | #define DID_RESET 0x08 /* reset by somebody */ |
| 137 | #define DID_BAD_INTR 0x09 /* unexpected interrupt */ |
| 138 | #define DID_PASSTHROUGH 0x0a /* passthrough */ |
| 139 | #define DID_SOFT_ERROR 0x0b /* low driver wants retry */ |
| 140 | #define DID_IMM_RETRY 0x0c /* retry without decreasing retrycnt */ |
| 141 | |
| 142 | /* |
| 143 | * Driver codes |
| 144 | */ |
| 145 | #define DRIVER_OK 0x00 |
| 146 | #define DRIVER_BUSY 0x01 |
| 147 | #define DRIVER_SOFT 0x02 |
| 148 | #define DRIVER_MEDIA 0x03 |
| 149 | #define DRIVER_ERROR 0x04 |
| 150 | |
| 151 | #define DRIVER_INVALID 0x05 |
| 152 | #define DRIVER_TIMEOUT 0x06 |
| 153 | #define DRIVER_HARD 0x07 |
| 154 | #define DRIVER_SENSE 0x08 |
| 155 | |
| 156 | #define SUGGEST_RETRY 0x10 |
| 157 | #define SUGGEST_ABORT 0x20 |
| 158 | #define SUGGEST_REMAP 0x30 |
| 159 | #define SUGGEST_DIE 0x40 |
| 160 | #define SUGGEST_SENSE 0x80 |
| 161 | #define SUGGEST_IS_OK 0xff |
| 162 | |
| 163 | #define DRIVER_MASK 0x0f |
| 164 | #define SUGGEST_MASK 0xf0 |
| 165 | |
| 166 | /* Other definitions */ |
| 167 | /* HZ isn't always available, so simulate it */ |
| 168 | #define SG_DEFAULT_HZ 1000 |
| 169 | #define SG_DEFAULT_TIMEOUT (60*SG_DEFAULT_HZ) |
| 170 | |
| 171 | #endif /* !_SCSI_SG_H */ |