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