1168477Sscottl/* 2168477Sscottl * Structures and definitions for SCSI commands to the SG passthrough device. 3168477Sscottl * 4168477Sscottl * $FreeBSD: releng/10.2/sys/cam/scsi/scsi_sg.h 268139 2014-07-02 10:16:12Z mav $ 5168477Sscottl */ 6168477Sscottl 7168477Sscottl#ifndef _SCSI_SG_H 8168477Sscottl#define _SCSI_SG_H 9168477Sscottl 10168477Sscottl#define SGIOC '"' 11268139Smav#define SG_SET_TIMEOUT _IOW(SGIOC, 0x01, u_int) 12168477Sscottl#define SG_GET_TIMEOUT _IO(SGIOC, 0x02) 13268139Smav#define SG_EMULATED_HOST _IOR(SGIOC, 0x03, int) 14168477Sscottl#define SG_SET_TRANSFORM _IO(SGIOC, 0x04) 15168477Sscottl#define SG_GET_TRANSFORM _IO(SGIOC, 0x05) 16268139Smav#define SG_GET_COMMAND_Q _IOW(SGIOC, 0x70, int) 17268139Smav#define SG_SET_COMMAND_Q _IOR(SGIOC, 0x71, int) 18268139Smav#define SG_GET_RESERVED_SIZE _IOR(SGIOC, 0x72, int) 19268139Smav#define SG_SET_RESERVED_SIZE _IOW(SGIOC, 0x75, int) 20268139Smav#define SG_GET_SCSI_ID _IOR(SGIOC, 0x76, struct sg_scsi_id) 21268139Smav#define SG_SET_FORCE_LOW_DMA _IOW(SGIOC, 0x79, int) 22268139Smav#define SG_GET_LOW_DMA _IOR(SGIOC, 0x7a, int) 23268139Smav#define SG_SET_FORCE_PACK_ID _IOW(SGIOC, 0x7b, int) 24268139Smav#define SG_GET_PACK_ID _IOR(SGIOC, 0x7c, int) 25268139Smav#define SG_GET_NUM_WAITING _IOR(SGIOC, 0x7d, int) 26268139Smav#define SG_SET_DEBUG _IOW(SGIOC, 0x7e, int) 27268139Smav#define SG_GET_SG_TABLESIZE _IOR(SGIOC, 0x7f, int) 28268139Smav#define SG_GET_VERSION_NUM _IOR(SGIOC, 0x82, int) 29268139Smav#define SG_NEXT_CMD_LEN _IOW(SGIOC, 0x83, int) 30268139Smav#define SG_SCSI_RESET _IOW(SGIOC, 0x84, int) 31268139Smav#define SG_IO _IOWR(SGIOC, 0x85, struct sg_io_hdr) 32168477Sscottl#define SG_GET_REQUEST_TABLE _IO(SGIOC, 0x86) 33268139Smav#define SG_SET_KEEP_ORPHAN _IOW(SGIOC, 0x87, int) 34268139Smav#define SG_GET_KEEP_ORPHAN _IOR(SGIOC, 0x88, int) 35268139Smav#define SG_GET_ACCESS_COUNT _IOR(SGIOC, 0x89, int) 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 62268139Smavstruct sg_io_hdr32 { 63268139Smav int interface_id; 64268139Smav int dxfer_direction; 65268139Smav u_char cmd_len; 66268139Smav u_char mx_sb_len; 67268139Smav u_short iovec_count; 68268139Smav u_int dxfer_len; 69268139Smav uint32_t dxferp; 70268139Smav uint32_t cmdp; 71268139Smav uint32_t sbp; 72268139Smav u_int timeout; 73268139Smav u_int flags; 74268139Smav int pack_id; 75268139Smav uint32_t usr_ptr; 76268139Smav u_char status; 77268139Smav u_char masked_status; 78268139Smav u_char msg_status; 79268139Smav u_char sb_len_wr; 80268139Smav u_short host_status; 81268139Smav u_short driver_status; 82268139Smav int resid; 83268139Smav u_int duration; 84268139Smav u_int info; 85268139Smav}; 86268139Smav 87168477Sscottl#define SG_DXFER_NONE -1 88168477Sscottl#define SG_DXFER_TO_DEV -2 89168477Sscottl#define SG_DXFER_FROM_DEV -3 90168477Sscottl#define SG_DXFER_TO_FROM_DEV -4 91168477Sscottl#define SG_DXFER_UNKNOWN -5 92168477Sscottl 93168477Sscottl#define SG_MAX_SENSE 16 94168477Sscottlstruct sg_header { 95168477Sscottl int pack_len; 96168477Sscottl int reply_len; 97168477Sscottl int pack_id; 98168477Sscottl int result; 99168477Sscottl u_int twelve_byte:1; 100168477Sscottl u_int target_status:5; 101168477Sscottl u_int host_status:8; 102168477Sscottl u_int driver_status:8; 103168477Sscottl u_int other_flags:10; 104168477Sscottl u_char sense_buffer[SG_MAX_SENSE]; 105168477Sscottl}; 106168477Sscottl 107168477Sscottlstruct sg_scsi_id { 108168477Sscottl int host_no; 109168477Sscottl int channel; 110168477Sscottl int scsi_id; 111168477Sscottl int lun; 112168477Sscottl int scsi_type; 113168477Sscottl short h_cmd_per_lun; 114168477Sscottl short d_queue_depth; 115168477Sscottl int unused[2]; 116168477Sscottl}; 117168477Sscottl 118168477Sscottlstruct scsi_idlun { 119168477Sscottl uint32_t dev_id; 120168477Sscottl uint32_t host_unique_id; 121168477Sscottl}; 122168477Sscottl 123168477Sscottl/* 124168477Sscottl * Host codes 125168477Sscottl */ 126168477Sscottl#define DID_OK 0x00 /* OK */ 127168477Sscottl#define DID_NO_CONNECT 0x01 /* timeout during connect */ 128168477Sscottl#define DID_BUS_BUSY 0x02 /* timeout during command */ 129168477Sscottl#define DID_TIME_OUT 0x03 /* other timeout */ 130168477Sscottl#define DID_BAD_TARGET 0x04 /* bad target */ 131168477Sscottl#define DID_ABORT 0x05 /* abort */ 132168477Sscottl#define DID_PARITY 0x06 /* parity error */ 133168477Sscottl#define DID_ERROR 0x07 /* internal error */ 134168477Sscottl#define DID_RESET 0x08 /* reset by somebody */ 135168477Sscottl#define DID_BAD_INTR 0x09 /* unexpected interrupt */ 136168477Sscottl#define DID_PASSTHROUGH 0x0a /* passthrough */ 137168477Sscottl#define DID_SOFT_ERROR 0x0b /* low driver wants retry */ 138168477Sscottl#define DID_IMM_RETRY 0x0c /* retry without decreasing retrycnt */ 139168477Sscottl 140168477Sscottl/* 141168477Sscottl * Driver codes 142168477Sscottl */ 143168477Sscottl#define DRIVER_OK 0x00 144168477Sscottl#define DRIVER_BUSY 0x01 145168477Sscottl#define DRIVER_SOFT 0x02 146168477Sscottl#define DRIVER_MEDIA 0x03 147168477Sscottl#define DRIVER_ERROR 0x04 148168477Sscottl 149168477Sscottl#define DRIVER_INVALID 0x05 150168477Sscottl#define DRIVER_TIMEOUT 0x06 151168477Sscottl#define DRIVER_HARD 0x07 152168477Sscottl#define DRIVER_SENSE 0x08 153168477Sscottl 154168477Sscottl#define SUGGEST_RETRY 0x10 155168477Sscottl#define SUGGEST_ABORT 0x20 156168477Sscottl#define SUGGEST_REMAP 0x30 157168477Sscottl#define SUGGEST_DIE 0x40 158168477Sscottl#define SUGGEST_SENSE 0x80 159168477Sscottl#define SUGGEST_IS_OK 0xff 160168477Sscottl 161168477Sscottl#define DRIVER_MASK 0x0f 162168477Sscottl#define SUGGEST_MASK 0xf0 163168477Sscottl 164168598Sscottl/* Other definitions */ 165168598Sscottl/* HZ isn't always available, so simulate it */ 166168598Sscottl#define SG_DEFAULT_HZ 1000 167168598Sscottl#define SG_DEFAULT_TIMEOUT (60*SG_DEFAULT_HZ) 168168598Sscottl 169168477Sscottl#endif /* !_SCSI_SG_H */ 170