11eba4c79SScott Long /* 21eba4c79SScott Long * Structures and definitions for SCSI commands to the SG passthrough device. 31eba4c79SScott Long * 41eba4c79SScott Long * $FreeBSD$ 51eba4c79SScott Long */ 61eba4c79SScott Long 71eba4c79SScott Long #ifndef _SCSI_SG_H 81eba4c79SScott Long #define _SCSI_SG_H 91eba4c79SScott Long 101eba4c79SScott Long #define SGIOC '"' 111eba4c79SScott Long #define SG_SET_TIMEOUT _IO(SGIOC, 0x01) 121eba4c79SScott Long #define SG_GET_TIMEOUT _IO(SGIOC, 0x02) 131eba4c79SScott Long #define SG_EMULATED_HOST _IO(SGIOC, 0x03) 141eba4c79SScott Long #define SG_SET_TRANSFORM _IO(SGIOC, 0x04) 151eba4c79SScott Long #define SG_GET_TRANSFORM _IO(SGIOC, 0x05) 161eba4c79SScott Long #define SG_GET_COMMAND_Q _IO(SGIOC, 0x70) 171eba4c79SScott Long #define SG_SET_COMMAND_Q _IO(SGIOC, 0x71) 181eba4c79SScott Long #define SG_GET_RESERVED_SIZE _IO(SGIOC, 0x72) 191eba4c79SScott Long #define SG_SET_RESERVED_SIZE _IO(SGIOC, 0x75) 201eba4c79SScott Long #define SG_GET_SCSI_ID _IO(SGIOC, 0x76) 211eba4c79SScott Long #define SG_SET_FORCE_LOW_DMA _IO(SGIOC, 0x79) 221eba4c79SScott Long #define SG_GET_LOW_DMA _IO(SGIOC, 0x7a) 231eba4c79SScott Long #define SG_SET_FORCE_PACK_ID _IO(SGIOC, 0x7b) 241eba4c79SScott Long #define SG_GET_PACK_ID _IO(SGIOC, 0x7c) 251eba4c79SScott Long #define SG_GET_NUM_WAITING _IO(SGIOC, 0x7d) 261eba4c79SScott Long #define SG_SET_DEBUG _IO(SGIOC, 0x7e) 271eba4c79SScott Long #define SG_GET_SG_TABLESIZE _IO(SGIOC, 0x7f) 281eba4c79SScott Long #define SG_GET_VERSION_NUM _IO(SGIOC, 0x82) 291eba4c79SScott Long #define SG_NEXT_CMD_LEN _IO(SGIOC, 0x83) 301eba4c79SScott Long #define SG_SCSI_RESET _IO(SGIOC, 0x84) 311eba4c79SScott Long #define SG_IO _IO(SGIOC, 0x85) 321eba4c79SScott Long #define SG_GET_REQUEST_TABLE _IO(SGIOC, 0x86) 331eba4c79SScott Long #define SG_SET_KEEP_ORPHAN _IO(SGIOC, 0x87) 341eba4c79SScott Long #define SG_GET_KEEP_ORPHAN _IO(SGIOC, 0x88) 351eba4c79SScott Long #define SG_GET_ACCESS_COUNT _IO(SGIOC, 0x89) 361eba4c79SScott Long 371eba4c79SScott Long struct sg_io_hdr { 381eba4c79SScott Long int interface_id; 391eba4c79SScott Long int dxfer_direction; 401eba4c79SScott Long u_char cmd_len; 411eba4c79SScott Long u_char mx_sb_len; 421eba4c79SScott Long u_short iovec_count; 431eba4c79SScott Long u_int dxfer_len; 441eba4c79SScott Long void *dxferp; 451eba4c79SScott Long u_char *cmdp; 461eba4c79SScott Long u_char *sbp; 471eba4c79SScott Long u_int timeout; 481eba4c79SScott Long u_int flags; 491eba4c79SScott Long int pack_id; 501eba4c79SScott Long void *usr_ptr; 511eba4c79SScott Long u_char status; 521eba4c79SScott Long u_char masked_status; 531eba4c79SScott Long u_char msg_status; 541eba4c79SScott Long u_char sb_len_wr; 551eba4c79SScott Long u_short host_status; 561eba4c79SScott Long u_short driver_status; 571eba4c79SScott Long int resid; 581eba4c79SScott Long u_int duration; 591eba4c79SScott Long u_int info; 601eba4c79SScott Long }; 611eba4c79SScott Long 621eba4c79SScott Long #define SG_DXFER_NONE -1 631eba4c79SScott Long #define SG_DXFER_TO_DEV -2 641eba4c79SScott Long #define SG_DXFER_FROM_DEV -3 651eba4c79SScott Long #define SG_DXFER_TO_FROM_DEV -4 661eba4c79SScott Long #define SG_DXFER_UNKNOWN -5 671eba4c79SScott Long 681eba4c79SScott Long #define SG_MAX_SENSE 16 691eba4c79SScott Long struct sg_header { 701eba4c79SScott Long int pack_len; 711eba4c79SScott Long int reply_len; 721eba4c79SScott Long int pack_id; 731eba4c79SScott Long int result; 741eba4c79SScott Long u_int twelve_byte:1; 751eba4c79SScott Long u_int target_status:5; 761eba4c79SScott Long u_int host_status:8; 771eba4c79SScott Long u_int driver_status:8; 781eba4c79SScott Long u_int other_flags:10; 791eba4c79SScott Long u_char sense_buffer[SG_MAX_SENSE]; 801eba4c79SScott Long }; 811eba4c79SScott Long 821eba4c79SScott Long struct sg_scsi_id { 831eba4c79SScott Long int host_no; 841eba4c79SScott Long int channel; 851eba4c79SScott Long int scsi_id; 861eba4c79SScott Long int lun; 871eba4c79SScott Long int scsi_type; 881eba4c79SScott Long short h_cmd_per_lun; 891eba4c79SScott Long short d_queue_depth; 901eba4c79SScott Long int unused[2]; 911eba4c79SScott Long }; 921eba4c79SScott Long 931eba4c79SScott Long struct scsi_idlun { 941eba4c79SScott Long uint32_t dev_id; 951eba4c79SScott Long uint32_t host_unique_id; 961eba4c79SScott Long }; 971eba4c79SScott Long 981eba4c79SScott Long /* 991eba4c79SScott Long * Host codes 1001eba4c79SScott Long */ 1011eba4c79SScott Long #define DID_OK 0x00 /* OK */ 1021eba4c79SScott Long #define DID_NO_CONNECT 0x01 /* timeout during connect */ 1031eba4c79SScott Long #define DID_BUS_BUSY 0x02 /* timeout during command */ 1041eba4c79SScott Long #define DID_TIME_OUT 0x03 /* other timeout */ 1051eba4c79SScott Long #define DID_BAD_TARGET 0x04 /* bad target */ 1061eba4c79SScott Long #define DID_ABORT 0x05 /* abort */ 1071eba4c79SScott Long #define DID_PARITY 0x06 /* parity error */ 1081eba4c79SScott Long #define DID_ERROR 0x07 /* internal error */ 1091eba4c79SScott Long #define DID_RESET 0x08 /* reset by somebody */ 1101eba4c79SScott Long #define DID_BAD_INTR 0x09 /* unexpected interrupt */ 1111eba4c79SScott Long #define DID_PASSTHROUGH 0x0a /* passthrough */ 1121eba4c79SScott Long #define DID_SOFT_ERROR 0x0b /* low driver wants retry */ 1131eba4c79SScott Long #define DID_IMM_RETRY 0x0c /* retry without decreasing retrycnt */ 1141eba4c79SScott Long 1151eba4c79SScott Long /* 1161eba4c79SScott Long * Driver codes 1171eba4c79SScott Long */ 1181eba4c79SScott Long #define DRIVER_OK 0x00 1191eba4c79SScott Long #define DRIVER_BUSY 0x01 1201eba4c79SScott Long #define DRIVER_SOFT 0x02 1211eba4c79SScott Long #define DRIVER_MEDIA 0x03 1221eba4c79SScott Long #define DRIVER_ERROR 0x04 1231eba4c79SScott Long 1241eba4c79SScott Long #define DRIVER_INVALID 0x05 1251eba4c79SScott Long #define DRIVER_TIMEOUT 0x06 1261eba4c79SScott Long #define DRIVER_HARD 0x07 1271eba4c79SScott Long #define DRIVER_SENSE 0x08 1281eba4c79SScott Long 1291eba4c79SScott Long #define SUGGEST_RETRY 0x10 1301eba4c79SScott Long #define SUGGEST_ABORT 0x20 1311eba4c79SScott Long #define SUGGEST_REMAP 0x30 1321eba4c79SScott Long #define SUGGEST_DIE 0x40 1331eba4c79SScott Long #define SUGGEST_SENSE 0x80 1341eba4c79SScott Long #define SUGGEST_IS_OK 0xff 1351eba4c79SScott Long 1361eba4c79SScott Long #define DRIVER_MASK 0x0f 1371eba4c79SScott Long #define SUGGEST_MASK 0xf0 1381eba4c79SScott Long 139715ab212SScott Long /* Other definitions */ 140715ab212SScott Long /* HZ isn't always available, so simulate it */ 141715ab212SScott Long #define SG_DEFAULT_HZ 1000 142715ab212SScott Long #define SG_DEFAULT_TIMEOUT (60*SG_DEFAULT_HZ) 143715ab212SScott Long 1441eba4c79SScott Long #endif /* !_SCSI_SG_H */ 145