Kernel - Add scsi/scsi_sg linux-compatible SCSI pass through device
[dragonfly.git] / sys / bus / cam / scsi / scsi_sg.h
1 /*
2  * Structures and definitions for SCSI commands to the SG passthrough device.
3  *
4  * $FreeBSD: src/sys/cam/scsi/scsi_sg.h,v 1.2 2007/04/10 20:03:42 scottl Exp $
5  */
6
7 #ifndef _SCSI_SG_H
8 #define _SCSI_SG_H
9
10 #define SGIOC   '"'
11 #define SG_SET_TIMEOUT          _IO(SGIOC, 0x01)
12 #define SG_GET_TIMEOUT          _IO(SGIOC, 0x02)
13 #define SG_EMULATED_HOST        _IO(SGIOC, 0x03)
14 #define SG_SET_TRANSFORM        _IO(SGIOC, 0x04)
15 #define SG_GET_TRANSFORM        _IO(SGIOC, 0x05)
16 #define SG_GET_COMMAND_Q        _IO(SGIOC, 0x70)
17 #define SG_SET_COMMAND_Q        _IO(SGIOC, 0x71)
18 #define SG_GET_RESERVED_SIZE    _IO(SGIOC, 0x72)
19 #define SG_SET_RESERVED_SIZE    _IO(SGIOC, 0x75)
20 #define SG_GET_SCSI_ID          _IO(SGIOC, 0x76)
21 #define SG_SET_FORCE_LOW_DMA    _IO(SGIOC, 0x79)
22 #define SG_GET_LOW_DMA          _IO(SGIOC, 0x7a)
23 #define SG_SET_FORCE_PACK_ID    _IO(SGIOC, 0x7b)
24 #define SG_GET_PACK_ID          _IO(SGIOC, 0x7c)
25 #define SG_GET_NUM_WAITING      _IO(SGIOC, 0x7d)
26 #define SG_SET_DEBUG            _IO(SGIOC, 0x7e)
27 #define SG_GET_SG_TABLESIZE     _IO(SGIOC, 0x7f)
28 #define SG_GET_VERSION_NUM      _IO(SGIOC, 0x82)
29 #define SG_NEXT_CMD_LEN         _IO(SGIOC, 0x83)
30 #define SG_SCSI_RESET           _IO(SGIOC, 0x84)
31 #define SG_IO                   _IO(SGIOC, 0x85)
32 #define SG_GET_REQUEST_TABLE    _IO(SGIOC, 0x86)
33 #define SG_SET_KEEP_ORPHAN      _IO(SGIOC, 0x87)
34 #define SG_GET_KEEP_ORPHAN      _IO(SGIOC, 0x88)
35 #define SG_GET_ACCESS_COUNT     _IO(SGIOC, 0x89)
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 #define SG_DXFER_NONE           -1
63 #define SG_DXFER_TO_DEV         -2
64 #define SG_DXFER_FROM_DEV       -3
65 #define SG_DXFER_TO_FROM_DEV    -4
66 #define SG_DXFER_UNKNOWN        -5
67
68 #define SG_MAX_SENSE            16
69
70 struct sg_header {
71         int             pack_len;
72         int             reply_len;
73         int             pack_id;
74         int             result;
75         u_int           twelve_byte:1;
76         u_int           target_status:5;
77         u_int           host_status:8;
78         u_int           driver_status:8;
79         u_int           other_flags:10;
80         u_char          sense_buffer[SG_MAX_SENSE];
81 };
82
83 struct sg_scsi_id {
84         int             host_no;
85         int             channel;
86         int             scsi_id;
87         int             lun;
88         int             scsi_type;
89         short           h_cmd_per_lun;
90         short           d_queue_depth;
91         int             unused[2];
92 };
93
94 struct scsi_idlun {
95         uint32_t        dev_id;
96         uint32_t        host_unique_id;
97 };
98
99 /*
100  * Host codes
101  */
102 #define DID_OK          0x00    /* OK */
103 #define DID_NO_CONNECT  0x01    /* timeout during connect */
104 #define DID_BUS_BUSY    0x02    /* timeout during command */
105 #define DID_TIME_OUT    0x03    /* other timeout */
106 #define DID_BAD_TARGET  0x04    /* bad target */
107 #define DID_ABORT       0x05    /* abort */
108 #define DID_PARITY      0x06    /* parity error */
109 #define DID_ERROR       0x07    /* internal error */
110 #define DID_RESET       0x08    /* reset by somebody */
111 #define DID_BAD_INTR    0x09    /* unexpected interrupt */
112 #define DID_PASSTHROUGH 0x0a    /* passthrough */
113 #define DID_SOFT_ERROR  0x0b    /* low driver wants retry */
114 #define DID_IMM_RETRY   0x0c    /* retry without decreasing retrycnt */
115
116 /*
117  * Driver codes
118  */
119 #define DRIVER_OK       0x00
120 #define DRIVER_BUSY     0x01
121 #define DRIVER_SOFT     0x02
122 #define DRIVER_MEDIA    0x03
123 #define DRIVER_ERROR    0x04
124
125 #define DRIVER_INVALID  0x05
126 #define DRIVER_TIMEOUT  0x06
127 #define DRIVER_HARD     0x07
128 #define DRIVER_SENSE    0x08
129
130 #define SUGGEST_RETRY   0x10
131 #define SUGGEST_ABORT   0x20
132 #define SUGGEST_REMAP   0x30
133 #define SUGGEST_DIE     0x40
134 #define SUGGEST_SENSE   0x80
135 #define SUGGEST_IS_OK   0xff
136
137 #define DRIVER_MASK     0x0f
138 #define SUGGEST_MASK    0xf0
139
140 /* Other definitions */
141 /* HZ isn't always available, so simulate it */
142 #define SG_DEFAULT_HZ           1000
143 #define SG_DEFAULT_TIMEOUT      (60*SG_DEFAULT_HZ)
144
145 #endif /* !_SCSI_SG_H */