xref: /dragonfly/sys/bus/cam/scsi/scsi_sg.h (revision d1d6f4eb)
1388705e4SMatthew Dillon /*
2388705e4SMatthew Dillon  * Structures and definitions for SCSI commands to the SG passthrough device.
3388705e4SMatthew Dillon  *
4388705e4SMatthew Dillon  * $FreeBSD: src/sys/cam/scsi/scsi_sg.h,v 1.2 2007/04/10 20:03:42 scottl Exp $
5388705e4SMatthew Dillon  */
6388705e4SMatthew Dillon 
7388705e4SMatthew Dillon #ifndef _SCSI_SG_H
8388705e4SMatthew Dillon #define _SCSI_SG_H
9388705e4SMatthew Dillon 
10*d1d6f4ebSSascha Wildner #include <sys/ioccom.h>
11*d1d6f4ebSSascha Wildner 
12388705e4SMatthew Dillon #define SGIOC	'"'
13388705e4SMatthew Dillon #define SG_SET_TIMEOUT		_IO(SGIOC, 0x01)
14388705e4SMatthew Dillon #define SG_GET_TIMEOUT		_IO(SGIOC, 0x02)
15388705e4SMatthew Dillon #define SG_EMULATED_HOST	_IO(SGIOC, 0x03)
16388705e4SMatthew Dillon #define SG_SET_TRANSFORM	_IO(SGIOC, 0x04)
17388705e4SMatthew Dillon #define SG_GET_TRANSFORM	_IO(SGIOC, 0x05)
18388705e4SMatthew Dillon #define SG_GET_COMMAND_Q	_IO(SGIOC, 0x70)
19388705e4SMatthew Dillon #define SG_SET_COMMAND_Q	_IO(SGIOC, 0x71)
20388705e4SMatthew Dillon #define SG_GET_RESERVED_SIZE	_IO(SGIOC, 0x72)
21388705e4SMatthew Dillon #define SG_SET_RESERVED_SIZE	_IO(SGIOC, 0x75)
22388705e4SMatthew Dillon #define SG_GET_SCSI_ID		_IO(SGIOC, 0x76)
23388705e4SMatthew Dillon #define SG_SET_FORCE_LOW_DMA	_IO(SGIOC, 0x79)
24388705e4SMatthew Dillon #define SG_GET_LOW_DMA		_IO(SGIOC, 0x7a)
25388705e4SMatthew Dillon #define SG_SET_FORCE_PACK_ID	_IO(SGIOC, 0x7b)
26388705e4SMatthew Dillon #define SG_GET_PACK_ID		_IO(SGIOC, 0x7c)
27388705e4SMatthew Dillon #define SG_GET_NUM_WAITING	_IO(SGIOC, 0x7d)
28388705e4SMatthew Dillon #define SG_SET_DEBUG		_IO(SGIOC, 0x7e)
29388705e4SMatthew Dillon #define SG_GET_SG_TABLESIZE	_IO(SGIOC, 0x7f)
30388705e4SMatthew Dillon #define SG_GET_VERSION_NUM	_IO(SGIOC, 0x82)
31388705e4SMatthew Dillon #define SG_NEXT_CMD_LEN		_IO(SGIOC, 0x83)
32388705e4SMatthew Dillon #define SG_SCSI_RESET		_IO(SGIOC, 0x84)
33388705e4SMatthew Dillon #define SG_IO			_IO(SGIOC, 0x85)
34388705e4SMatthew Dillon #define SG_GET_REQUEST_TABLE	_IO(SGIOC, 0x86)
35388705e4SMatthew Dillon #define SG_SET_KEEP_ORPHAN	_IO(SGIOC, 0x87)
36388705e4SMatthew Dillon #define SG_GET_KEEP_ORPHAN	_IO(SGIOC, 0x88)
37388705e4SMatthew Dillon #define SG_GET_ACCESS_COUNT	_IO(SGIOC, 0x89)
38388705e4SMatthew Dillon 
39388705e4SMatthew Dillon struct sg_io_hdr {
40388705e4SMatthew Dillon 	int		interface_id;
41388705e4SMatthew Dillon 	int		dxfer_direction;
42388705e4SMatthew Dillon 	u_char		cmd_len;
43388705e4SMatthew Dillon 	u_char		mx_sb_len;
44388705e4SMatthew Dillon 	u_short		iovec_count;
45388705e4SMatthew Dillon 	u_int		dxfer_len;
46388705e4SMatthew Dillon 	void		*dxferp;
47388705e4SMatthew Dillon 	u_char		*cmdp;
48388705e4SMatthew Dillon 	u_char		*sbp;
49388705e4SMatthew Dillon 	u_int		timeout;
50388705e4SMatthew Dillon 	u_int		flags;
51388705e4SMatthew Dillon 	int		pack_id;
52388705e4SMatthew Dillon 	void		*usr_ptr;
53388705e4SMatthew Dillon 	u_char		status;
54388705e4SMatthew Dillon 	u_char		masked_status;
55388705e4SMatthew Dillon 	u_char		msg_status;
56388705e4SMatthew Dillon 	u_char		sb_len_wr;
57388705e4SMatthew Dillon 	u_short		host_status;
58388705e4SMatthew Dillon 	u_short		driver_status;
59388705e4SMatthew Dillon 	int		resid;
60388705e4SMatthew Dillon 	u_int		duration;
61388705e4SMatthew Dillon 	u_int		info;
62388705e4SMatthew Dillon };
63388705e4SMatthew Dillon 
64388705e4SMatthew Dillon #define SG_DXFER_NONE		-1
65388705e4SMatthew Dillon #define SG_DXFER_TO_DEV		-2
66388705e4SMatthew Dillon #define SG_DXFER_FROM_DEV	-3
67388705e4SMatthew Dillon #define SG_DXFER_TO_FROM_DEV	-4
68388705e4SMatthew Dillon #define SG_DXFER_UNKNOWN	-5
69388705e4SMatthew Dillon 
70388705e4SMatthew Dillon #define SG_MAX_SENSE            16
71388705e4SMatthew Dillon 
72388705e4SMatthew Dillon struct sg_header {
73388705e4SMatthew Dillon 	int		pack_len;
74388705e4SMatthew Dillon 	int		reply_len;
75388705e4SMatthew Dillon 	int		pack_id;
76388705e4SMatthew Dillon 	int		result;
77388705e4SMatthew Dillon 	u_int		twelve_byte:1;
78388705e4SMatthew Dillon 	u_int		target_status:5;
79388705e4SMatthew Dillon 	u_int		host_status:8;
80388705e4SMatthew Dillon 	u_int		driver_status:8;
81388705e4SMatthew Dillon 	u_int		other_flags:10;
82388705e4SMatthew Dillon 	u_char		sense_buffer[SG_MAX_SENSE];
83388705e4SMatthew Dillon };
84388705e4SMatthew Dillon 
85388705e4SMatthew Dillon struct sg_scsi_id {
86388705e4SMatthew Dillon 	int		host_no;
87388705e4SMatthew Dillon 	int		channel;
88388705e4SMatthew Dillon 	int		scsi_id;
89388705e4SMatthew Dillon 	int		lun;
90388705e4SMatthew Dillon 	int		scsi_type;
91388705e4SMatthew Dillon 	short		h_cmd_per_lun;
92388705e4SMatthew Dillon 	short		d_queue_depth;
93388705e4SMatthew Dillon 	int		unused[2];
94388705e4SMatthew Dillon };
95388705e4SMatthew Dillon 
96388705e4SMatthew Dillon struct scsi_idlun {
97388705e4SMatthew Dillon 	uint32_t	dev_id;
98388705e4SMatthew Dillon 	uint32_t	host_unique_id;
99388705e4SMatthew Dillon };
100388705e4SMatthew Dillon 
101388705e4SMatthew Dillon /*
102388705e4SMatthew Dillon  * Host codes
103388705e4SMatthew Dillon  */
104388705e4SMatthew Dillon #define DID_OK		0x00	/* OK */
105388705e4SMatthew Dillon #define DID_NO_CONNECT	0x01	/* timeout during connect */
106388705e4SMatthew Dillon #define DID_BUS_BUSY	0x02	/* timeout during command */
107388705e4SMatthew Dillon #define DID_TIME_OUT	0x03	/* other timeout */
108388705e4SMatthew Dillon #define DID_BAD_TARGET	0x04	/* bad target */
109388705e4SMatthew Dillon #define DID_ABORT	0x05	/* abort */
110388705e4SMatthew Dillon #define DID_PARITY	0x06	/* parity error */
111388705e4SMatthew Dillon #define DID_ERROR	0x07	/* internal error */
112388705e4SMatthew Dillon #define DID_RESET	0x08	/* reset by somebody */
113388705e4SMatthew Dillon #define DID_BAD_INTR	0x09	/* unexpected interrupt */
114388705e4SMatthew Dillon #define DID_PASSTHROUGH	0x0a	/* passthrough */
115388705e4SMatthew Dillon #define DID_SOFT_ERROR	0x0b	/* low driver wants retry */
116388705e4SMatthew Dillon #define DID_IMM_RETRY	0x0c	/* retry without decreasing retrycnt */
117388705e4SMatthew Dillon 
118388705e4SMatthew Dillon /*
119388705e4SMatthew Dillon  * Driver codes
120388705e4SMatthew Dillon  */
121388705e4SMatthew Dillon #define DRIVER_OK	0x00
122388705e4SMatthew Dillon #define DRIVER_BUSY	0x01
123388705e4SMatthew Dillon #define DRIVER_SOFT	0x02
124388705e4SMatthew Dillon #define DRIVER_MEDIA	0x03
125388705e4SMatthew Dillon #define DRIVER_ERROR	0x04
126388705e4SMatthew Dillon 
127388705e4SMatthew Dillon #define DRIVER_INVALID	0x05
128388705e4SMatthew Dillon #define DRIVER_TIMEOUT	0x06
129388705e4SMatthew Dillon #define DRIVER_HARD	0x07
130388705e4SMatthew Dillon #define DRIVER_SENSE	0x08
131388705e4SMatthew Dillon 
132388705e4SMatthew Dillon #define SUGGEST_RETRY	0x10
133388705e4SMatthew Dillon #define SUGGEST_ABORT	0x20
134388705e4SMatthew Dillon #define SUGGEST_REMAP	0x30
135388705e4SMatthew Dillon #define SUGGEST_DIE	0x40
136388705e4SMatthew Dillon #define SUGGEST_SENSE	0x80
137388705e4SMatthew Dillon #define SUGGEST_IS_OK	0xff
138388705e4SMatthew Dillon 
139388705e4SMatthew Dillon #define DRIVER_MASK	0x0f
140388705e4SMatthew Dillon #define SUGGEST_MASK	0xf0
141388705e4SMatthew Dillon 
142388705e4SMatthew Dillon /* Other definitions */
143388705e4SMatthew Dillon /* HZ isn't always available, so simulate it */
144388705e4SMatthew Dillon #define SG_DEFAULT_HZ		1000
145388705e4SMatthew Dillon #define SG_DEFAULT_TIMEOUT	(60*SG_DEFAULT_HZ)
146388705e4SMatthew Dillon 
147388705e4SMatthew Dillon #endif /* !_SCSI_SG_H */
148