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