xref: /freebsd/sys/cam/scsi/scsi_sg.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
11eba4c79SScott Long /*
21eba4c79SScott Long  * Structures and definitions for SCSI commands to the SG passthrough device.
31eba4c79SScott Long  */
41eba4c79SScott Long 
51eba4c79SScott Long #ifndef _SCSI_SG_H
61eba4c79SScott Long #define _SCSI_SG_H
71eba4c79SScott Long 
81eba4c79SScott Long #define SGIOC	'"'
9*fcaf473cSAlexander Motin #define SG_SET_TIMEOUT		_IOW(SGIOC, 0x01, u_int)
101eba4c79SScott Long #define SG_GET_TIMEOUT		_IO(SGIOC, 0x02)
11*fcaf473cSAlexander Motin #define SG_EMULATED_HOST	_IOR(SGIOC, 0x03, int)
121eba4c79SScott Long #define SG_SET_TRANSFORM	_IO(SGIOC, 0x04)
131eba4c79SScott Long #define SG_GET_TRANSFORM	_IO(SGIOC, 0x05)
14*fcaf473cSAlexander Motin #define SG_GET_COMMAND_Q	_IOW(SGIOC, 0x70, int)
15*fcaf473cSAlexander Motin #define SG_SET_COMMAND_Q	_IOR(SGIOC, 0x71, int)
16*fcaf473cSAlexander Motin #define SG_GET_RESERVED_SIZE	_IOR(SGIOC, 0x72, int)
17*fcaf473cSAlexander Motin #define SG_SET_RESERVED_SIZE	_IOW(SGIOC, 0x75, int)
18*fcaf473cSAlexander Motin #define SG_GET_SCSI_ID		_IOR(SGIOC, 0x76, struct sg_scsi_id)
19*fcaf473cSAlexander Motin #define SG_SET_FORCE_LOW_DMA	_IOW(SGIOC, 0x79, int)
20*fcaf473cSAlexander Motin #define SG_GET_LOW_DMA		_IOR(SGIOC, 0x7a, int)
21*fcaf473cSAlexander Motin #define SG_SET_FORCE_PACK_ID	_IOW(SGIOC, 0x7b, int)
22*fcaf473cSAlexander Motin #define SG_GET_PACK_ID		_IOR(SGIOC, 0x7c, int)
23*fcaf473cSAlexander Motin #define SG_GET_NUM_WAITING	_IOR(SGIOC, 0x7d, int)
24*fcaf473cSAlexander Motin #define SG_SET_DEBUG		_IOW(SGIOC, 0x7e, int)
25*fcaf473cSAlexander Motin #define SG_GET_SG_TABLESIZE	_IOR(SGIOC, 0x7f, int)
26*fcaf473cSAlexander Motin #define SG_GET_VERSION_NUM	_IOR(SGIOC, 0x82, int)
27*fcaf473cSAlexander Motin #define SG_NEXT_CMD_LEN		_IOW(SGIOC, 0x83, int)
28*fcaf473cSAlexander Motin #define SG_SCSI_RESET		_IOW(SGIOC, 0x84, int)
29*fcaf473cSAlexander Motin #define SG_IO			_IOWR(SGIOC, 0x85, struct sg_io_hdr)
301eba4c79SScott Long #define SG_GET_REQUEST_TABLE	_IO(SGIOC, 0x86)
31*fcaf473cSAlexander Motin #define SG_SET_KEEP_ORPHAN	_IOW(SGIOC, 0x87, int)
32*fcaf473cSAlexander Motin #define SG_GET_KEEP_ORPHAN	_IOR(SGIOC, 0x88, int)
33*fcaf473cSAlexander Motin #define SG_GET_ACCESS_COUNT	_IOR(SGIOC, 0x89, int)
341eba4c79SScott Long 
351eba4c79SScott Long struct sg_io_hdr {
361eba4c79SScott Long 	int		interface_id;
371eba4c79SScott Long 	int		dxfer_direction;
381eba4c79SScott Long 	u_char		cmd_len;
391eba4c79SScott Long 	u_char		mx_sb_len;
401eba4c79SScott Long 	u_short		iovec_count;
411eba4c79SScott Long 	u_int		dxfer_len;
421eba4c79SScott Long 	void		*dxferp;
431eba4c79SScott Long 	u_char		*cmdp;
441eba4c79SScott Long 	u_char		*sbp;
451eba4c79SScott Long 	u_int		timeout;
461eba4c79SScott Long 	u_int		flags;
471eba4c79SScott Long 	int		pack_id;
481eba4c79SScott Long 	void		*usr_ptr;
491eba4c79SScott Long 	u_char		status;
501eba4c79SScott Long 	u_char		masked_status;
511eba4c79SScott Long 	u_char		msg_status;
521eba4c79SScott Long 	u_char		sb_len_wr;
531eba4c79SScott Long 	u_short		host_status;
541eba4c79SScott Long 	u_short		driver_status;
551eba4c79SScott Long 	int		resid;
561eba4c79SScott Long 	u_int		duration;
571eba4c79SScott Long 	u_int		info;
581eba4c79SScott Long };
591eba4c79SScott Long 
60*fcaf473cSAlexander Motin struct sg_io_hdr32 {
61*fcaf473cSAlexander Motin 	int		interface_id;
62*fcaf473cSAlexander Motin 	int		dxfer_direction;
63*fcaf473cSAlexander Motin 	u_char		cmd_len;
64*fcaf473cSAlexander Motin 	u_char		mx_sb_len;
65*fcaf473cSAlexander Motin 	u_short		iovec_count;
66*fcaf473cSAlexander Motin 	u_int		dxfer_len;
67*fcaf473cSAlexander Motin 	uint32_t	dxferp;
68*fcaf473cSAlexander Motin 	uint32_t	cmdp;
69*fcaf473cSAlexander Motin 	uint32_t	sbp;
70*fcaf473cSAlexander Motin 	u_int		timeout;
71*fcaf473cSAlexander Motin 	u_int		flags;
72*fcaf473cSAlexander Motin 	int		pack_id;
73*fcaf473cSAlexander Motin 	uint32_t	usr_ptr;
74*fcaf473cSAlexander Motin 	u_char		status;
75*fcaf473cSAlexander Motin 	u_char		masked_status;
76*fcaf473cSAlexander Motin 	u_char		msg_status;
77*fcaf473cSAlexander Motin 	u_char		sb_len_wr;
78*fcaf473cSAlexander Motin 	u_short		host_status;
79*fcaf473cSAlexander Motin 	u_short		driver_status;
80*fcaf473cSAlexander Motin 	int		resid;
81*fcaf473cSAlexander Motin 	u_int		duration;
82*fcaf473cSAlexander Motin 	u_int		info;
83*fcaf473cSAlexander Motin };
84*fcaf473cSAlexander Motin 
851eba4c79SScott Long #define SG_DXFER_NONE		-1
861eba4c79SScott Long #define SG_DXFER_TO_DEV		-2
871eba4c79SScott Long #define SG_DXFER_FROM_DEV	-3
881eba4c79SScott Long #define SG_DXFER_TO_FROM_DEV	-4
891eba4c79SScott Long #define SG_DXFER_UNKNOWN	-5
901eba4c79SScott Long 
911eba4c79SScott Long #define SG_MAX_SENSE 16
921eba4c79SScott Long struct sg_header {
931eba4c79SScott Long 	int		pack_len;
941eba4c79SScott Long 	int		reply_len;
951eba4c79SScott Long 	int		pack_id;
961eba4c79SScott Long 	int		result;
971eba4c79SScott Long 	u_int		twelve_byte:1;
981eba4c79SScott Long 	u_int		target_status:5;
991eba4c79SScott Long 	u_int		host_status:8;
1001eba4c79SScott Long 	u_int		driver_status:8;
1011eba4c79SScott Long 	u_int		other_flags:10;
1021eba4c79SScott Long 	u_char		sense_buffer[SG_MAX_SENSE];
1031eba4c79SScott Long };
1041eba4c79SScott Long 
1051eba4c79SScott Long struct sg_scsi_id {
1061eba4c79SScott Long 	int		host_no;
1071eba4c79SScott Long 	int		channel;
1081eba4c79SScott Long 	int		scsi_id;
1091eba4c79SScott Long 	int		lun;
1101eba4c79SScott Long 	int		scsi_type;
1111eba4c79SScott Long 	short		h_cmd_per_lun;
1121eba4c79SScott Long 	short		d_queue_depth;
1131eba4c79SScott Long 	int		unused[2];
1141eba4c79SScott Long };
1151eba4c79SScott Long 
1161eba4c79SScott Long struct scsi_idlun {
1171eba4c79SScott Long 	uint32_t	dev_id;
1181eba4c79SScott Long 	uint32_t	host_unique_id;
1191eba4c79SScott Long };
1201eba4c79SScott Long 
1211eba4c79SScott Long /*
1221eba4c79SScott Long  * Host codes
1231eba4c79SScott Long  */
1241eba4c79SScott Long #define DID_OK		0x00	/* OK */
1251eba4c79SScott Long #define DID_NO_CONNECT	0x01	/* timeout during connect */
1261eba4c79SScott Long #define DID_BUS_BUSY	0x02	/* timeout during command */
1271eba4c79SScott Long #define DID_TIME_OUT	0x03	/* other timeout */
1281eba4c79SScott Long #define DID_BAD_TARGET	0x04	/* bad target */
1291eba4c79SScott Long #define DID_ABORT	0x05	/* abort */
1301eba4c79SScott Long #define DID_PARITY	0x06	/* parity error */
1311eba4c79SScott Long #define DID_ERROR	0x07	/* internal error */
1321eba4c79SScott Long #define DID_RESET	0x08	/* reset by somebody */
1331eba4c79SScott Long #define DID_BAD_INTR	0x09	/* unexpected interrupt */
1341eba4c79SScott Long #define DID_PASSTHROUGH	0x0a	/* passthrough */
1351eba4c79SScott Long #define DID_SOFT_ERROR	0x0b	/* low driver wants retry */
1361eba4c79SScott Long #define DID_IMM_RETRY	0x0c	/* retry without decreasing retrycnt */
1371eba4c79SScott Long 
1381eba4c79SScott Long /*
1391eba4c79SScott Long  * Driver codes
1401eba4c79SScott Long  */
1411eba4c79SScott Long #define DRIVER_OK	0x00
1421eba4c79SScott Long #define DRIVER_BUSY	0x01
1431eba4c79SScott Long #define DRIVER_SOFT	0x02
1441eba4c79SScott Long #define DRIVER_MEDIA	0x03
1451eba4c79SScott Long #define DRIVER_ERROR	0x04
1461eba4c79SScott Long 
1471eba4c79SScott Long #define DRIVER_INVALID	0x05
1481eba4c79SScott Long #define DRIVER_TIMEOUT	0x06
1491eba4c79SScott Long #define DRIVER_HARD	0x07
1501eba4c79SScott Long #define DRIVER_SENSE	0x08
1511eba4c79SScott Long 
1521eba4c79SScott Long #define SUGGEST_RETRY	0x10
1531eba4c79SScott Long #define SUGGEST_ABORT	0x20
1541eba4c79SScott Long #define SUGGEST_REMAP	0x30
1551eba4c79SScott Long #define SUGGEST_DIE	0x40
1561eba4c79SScott Long #define SUGGEST_SENSE	0x80
1571eba4c79SScott Long #define SUGGEST_IS_OK	0xff
1581eba4c79SScott Long 
1591eba4c79SScott Long #define DRIVER_MASK	0x0f
1601eba4c79SScott Long #define SUGGEST_MASK	0xf0
1611eba4c79SScott Long 
162715ab212SScott Long /* Other definitions */
163715ab212SScott Long /* HZ isn't always available, so simulate it */
164715ab212SScott Long #define SG_DEFAULT_HZ		1000
165715ab212SScott Long #define SG_DEFAULT_TIMEOUT	(60*SG_DEFAULT_HZ)
166715ab212SScott Long 
1671eba4c79SScott Long #endif /* !_SCSI_SG_H */
168