1168477Sscottl/* 2168477Sscottl * Structures and definitions for SCSI commands to the SG passthrough device. 3168477Sscottl * 4168477Sscottl * $FreeBSD$ 5168477Sscottl */ 6168477Sscottl 7168477Sscottl#ifndef _SCSI_SG_H 8168477Sscottl#define _SCSI_SG_H 9168477Sscottl 10168477Sscottl#define SGIOC '"' 11168477Sscottl#define SG_SET_TIMEOUT _IO(SGIOC, 0x01) 12168477Sscottl#define SG_GET_TIMEOUT _IO(SGIOC, 0x02) 13168477Sscottl#define SG_EMULATED_HOST _IO(SGIOC, 0x03) 14168477Sscottl#define SG_SET_TRANSFORM _IO(SGIOC, 0x04) 15168477Sscottl#define SG_GET_TRANSFORM _IO(SGIOC, 0x05) 16168477Sscottl#define SG_GET_COMMAND_Q _IO(SGIOC, 0x70) 17168477Sscottl#define SG_SET_COMMAND_Q _IO(SGIOC, 0x71) 18168477Sscottl#define SG_GET_RESERVED_SIZE _IO(SGIOC, 0x72) 19168477Sscottl#define SG_SET_RESERVED_SIZE _IO(SGIOC, 0x75) 20168477Sscottl#define SG_GET_SCSI_ID _IO(SGIOC, 0x76) 21168477Sscottl#define SG_SET_FORCE_LOW_DMA _IO(SGIOC, 0x79) 22168477Sscottl#define SG_GET_LOW_DMA _IO(SGIOC, 0x7a) 23168477Sscottl#define SG_SET_FORCE_PACK_ID _IO(SGIOC, 0x7b) 24168477Sscottl#define SG_GET_PACK_ID _IO(SGIOC, 0x7c) 25168477Sscottl#define SG_GET_NUM_WAITING _IO(SGIOC, 0x7d) 26168477Sscottl#define SG_SET_DEBUG _IO(SGIOC, 0x7e) 27168477Sscottl#define SG_GET_SG_TABLESIZE _IO(SGIOC, 0x7f) 28168477Sscottl#define SG_GET_VERSION_NUM _IO(SGIOC, 0x82) 29168477Sscottl#define SG_NEXT_CMD_LEN _IO(SGIOC, 0x83) 30168477Sscottl#define SG_SCSI_RESET _IO(SGIOC, 0x84) 31168477Sscottl#define SG_IO _IO(SGIOC, 0x85) 32168477Sscottl#define SG_GET_REQUEST_TABLE _IO(SGIOC, 0x86) 33168477Sscottl#define SG_SET_KEEP_ORPHAN _IO(SGIOC, 0x87) 34168477Sscottl#define SG_GET_KEEP_ORPHAN _IO(SGIOC, 0x88) 35168477Sscottl#define SG_GET_ACCESS_COUNT _IO(SGIOC, 0x89) 36168477Sscottl 37168477Sscottlstruct sg_io_hdr { 38168477Sscottl int interface_id; 39168477Sscottl int dxfer_direction; 40168477Sscottl u_char cmd_len; 41168477Sscottl u_char mx_sb_len; 42168477Sscottl u_short iovec_count; 43168477Sscottl u_int dxfer_len; 44168477Sscottl void *dxferp; 45168477Sscottl u_char *cmdp; 46168477Sscottl u_char *sbp; 47168477Sscottl u_int timeout; 48168477Sscottl u_int flags; 49168477Sscottl int pack_id; 50168477Sscottl void *usr_ptr; 51168477Sscottl u_char status; 52168477Sscottl u_char masked_status; 53168477Sscottl u_char msg_status; 54168477Sscottl u_char sb_len_wr; 55168477Sscottl u_short host_status; 56168477Sscottl u_short driver_status; 57168477Sscottl int resid; 58168477Sscottl u_int duration; 59168477Sscottl u_int info; 60168477Sscottl}; 61168477Sscottl 62168477Sscottl#define SG_DXFER_NONE -1 63168477Sscottl#define SG_DXFER_TO_DEV -2 64168477Sscottl#define SG_DXFER_FROM_DEV -3 65168477Sscottl#define SG_DXFER_TO_FROM_DEV -4 66168477Sscottl#define SG_DXFER_UNKNOWN -5 67168477Sscottl 68168477Sscottl#define SG_MAX_SENSE 16 69168477Sscottlstruct sg_header { 70168477Sscottl int pack_len; 71168477Sscottl int reply_len; 72168477Sscottl int pack_id; 73168477Sscottl int result; 74168477Sscottl u_int twelve_byte:1; 75168477Sscottl u_int target_status:5; 76168477Sscottl u_int host_status:8; 77168477Sscottl u_int driver_status:8; 78168477Sscottl u_int other_flags:10; 79168477Sscottl u_char sense_buffer[SG_MAX_SENSE]; 80168477Sscottl}; 81168477Sscottl 82168477Sscottlstruct sg_scsi_id { 83168477Sscottl int host_no; 84168477Sscottl int channel; 85168477Sscottl int scsi_id; 86168477Sscottl int lun; 87168477Sscottl int scsi_type; 88168477Sscottl short h_cmd_per_lun; 89168477Sscottl short d_queue_depth; 90168477Sscottl int unused[2]; 91168477Sscottl}; 92168477Sscottl 93168477Sscottlstruct scsi_idlun { 94168477Sscottl uint32_t dev_id; 95168477Sscottl uint32_t host_unique_id; 96168477Sscottl}; 97168477Sscottl 98168477Sscottl/* 99168477Sscottl * Host codes 100168477Sscottl */ 101168477Sscottl#define DID_OK 0x00 /* OK */ 102168477Sscottl#define DID_NO_CONNECT 0x01 /* timeout during connect */ 103168477Sscottl#define DID_BUS_BUSY 0x02 /* timeout during command */ 104168477Sscottl#define DID_TIME_OUT 0x03 /* other timeout */ 105168477Sscottl#define DID_BAD_TARGET 0x04 /* bad target */ 106168477Sscottl#define DID_ABORT 0x05 /* abort */ 107168477Sscottl#define DID_PARITY 0x06 /* parity error */ 108168477Sscottl#define DID_ERROR 0x07 /* internal error */ 109168477Sscottl#define DID_RESET 0x08 /* reset by somebody */ 110168477Sscottl#define DID_BAD_INTR 0x09 /* unexpected interrupt */ 111168477Sscottl#define DID_PASSTHROUGH 0x0a /* passthrough */ 112168477Sscottl#define DID_SOFT_ERROR 0x0b /* low driver wants retry */ 113168477Sscottl#define DID_IMM_RETRY 0x0c /* retry without decreasing retrycnt */ 114168477Sscottl 115168477Sscottl/* 116168477Sscottl * Driver codes 117168477Sscottl */ 118168477Sscottl#define DRIVER_OK 0x00 119168477Sscottl#define DRIVER_BUSY 0x01 120168477Sscottl#define DRIVER_SOFT 0x02 121168477Sscottl#define DRIVER_MEDIA 0x03 122168477Sscottl#define DRIVER_ERROR 0x04 123168477Sscottl 124168477Sscottl#define DRIVER_INVALID 0x05 125168477Sscottl#define DRIVER_TIMEOUT 0x06 126168477Sscottl#define DRIVER_HARD 0x07 127168477Sscottl#define DRIVER_SENSE 0x08 128168477Sscottl 129168477Sscottl#define SUGGEST_RETRY 0x10 130168477Sscottl#define SUGGEST_ABORT 0x20 131168477Sscottl#define SUGGEST_REMAP 0x30 132168477Sscottl#define SUGGEST_DIE 0x40 133168477Sscottl#define SUGGEST_SENSE 0x80 134168477Sscottl#define SUGGEST_IS_OK 0xff 135168477Sscottl 136168477Sscottl#define DRIVER_MASK 0x0f 137168477Sscottl#define SUGGEST_MASK 0xf0 138168477Sscottl 139168598Sscottl/* Other definitions */ 140168598Sscottl/* HZ isn't always available, so simulate it */ 141168598Sscottl#define SG_DEFAULT_HZ 1000 142168598Sscottl#define SG_DEFAULT_TIMEOUT (60*SG_DEFAULT_HZ) 143168598Sscottl 144168477Sscottl#endif /* !_SCSI_SG_H */ 145