xref: /freebsd/sys/cam/scsi/scsi_targetio.h (revision 6990ffd8a95caaba6858ad44ff1b3157d1efba8f)
1 /*
2  * Ioctl definitions for the Target Mode SCSI Proccessor Target driver for CAM.
3  *
4  * Copyright (c) 1998 Justin T. Gibbs.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification, immediately at the beginning of the file.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _CAM_SCSI_SCSI_TARGETIO_H_
32 #define _CAM_SCSI_SCSI_TARGETIO_H_
33 #ifndef _KERNEL
34 #include <sys/types.h>
35 #endif
36 #include <sys/ioccom.h>
37 
38 #include <cam/cam.h>
39 #include <cam/cam_ccb.h>
40 
41 TAILQ_HEAD(ccb_queue, ccb_hdr);
42 
43 /* Determine and clear exception state in the driver */
44 typedef enum {
45 	TARG_EXCEPT_NONE	   = 0x00,
46 	TARG_EXCEPT_DEVICE_INVALID = 0x01,
47 	TARG_EXCEPT_BDR_RECEIVED   = 0x02,
48 	TARG_EXCEPT_BUS_RESET_SEEN = 0x04,
49 	TARG_EXCEPT_ABORT_SEEN	   = 0x08,
50 	TARG_EXCEPT_ABORT_TAG_SEEN = 0x10,
51 	TARG_EXCEPT_UNKNOWN_ATIO   = 0x80
52 } targ_exception;
53 
54 #define TARGIOCFETCHEXCEPTION	_IOR('C', 1, targ_exception)
55 #define TARGIOCCLEAREXCEPTION	_IOW('C', 2, targ_exception)
56 
57 /*
58  * Retreive an Accept Target I/O CCB for a command that is not handled
59  * directly by the kernel target driver.
60  */
61 #define TARGIOCFETCHATIO	_IOR('C', 3, struct ccb_accept_tio)
62 
63 /*
64  * Used for responding to incoming ATIO requests.  XPT_CONTINUE_TARG_IO
65  * operations are the norm, but ccb types for manipulating the device
66  * queue, etc. can also be used if error handling is to be performed by the
67  * user land process.
68  */
69 #define TARGIOCCOMMAND		_IOWR('C', 4, union ccb)
70 
71 
72 typedef enum {
73 	UA_NONE		= 0x00,
74 	UA_POWER_ON	= 0x01,
75 	UA_BUS_RESET	= 0x02,
76 	UA_BDR		= 0x04
77 } ua_types;
78 
79 typedef enum {
80 	CA_NONE		= 0x00,
81 	CA_UNIT_ATTN	= 0x01,
82 	CA_CMD_SENSE	= 0x02
83 } ca_types;
84 
85 struct initiator_state {
86 	ua_types   pending_ua;
87 	ca_types   pending_ca;
88 	struct	   scsi_sense_data sense_data;
89 	struct	   ccb_queue held_queue;
90 };
91 
92 struct ioc_initiator_state {
93 	u_int	initiator_id;
94 	struct	initiator_state istate;
95 };
96 
97 /*
98  * Get and Set Contingent Allegiance and Unit Attention state
99  * presented by the target driver.  This is usually used to
100  * properly report and error condition in response to an incoming
101  * ATIO request handled by the userland process.
102  *
103  * The initiator_id must be properly initialized in the ioc_initiator_state
104  * structure before calling TARGIOCGETISTATE.
105  */
106 #define TARGIOCGETISTATE	_IOWR('C', 6, struct ioc_initiator_state)
107 #define TARGIOCSETISTATE	_IOW('C', 5, struct ioc_initiator_state)
108 
109 struct old_ioc_alloc_unit {
110 	path_id_t	path_id;
111 	target_id_t	target_id;
112 	lun_id_t	lun_id;
113 	u_int		unit;
114 };
115 
116 struct ioc_alloc_unit {
117 	path_id_t	path_id;
118 	target_id_t	target_id;
119 	lun_id_t	lun_id;
120 	u_int		unit;
121 	struct scsi_inquiry_data *inquiry_data;
122 };
123 
124 /*
125  * Allocate and Free a target mode instance.  For allocation, the path_id,
126  * target_id, and lun_id fields must be set.  On successful completion
127  * of the ioctl, the unit field will indicate the unit number of the
128  * newly created instance.  For de-allocation, all fields must match
129  * an instance in the inactive (i.e. closed) state.
130  */
131 #define OTARGCTLIOALLOCUNIT	_IOWR('C', 7, struct old_ioc_alloc_unit)
132 #define OTARGCTLIOFREEUNIT	_IOW('C', 8, struct old_ioc_alloc_unit)
133 #define TARGCTLIOALLOCUNIT	_IOWR('C', 7, struct ioc_alloc_unit)
134 #define TARGCTLIOFREEUNIT	_IOW('C', 8, struct ioc_alloc_unit)
135 
136 /*
137  * Set/clear debugging for this target mode instance
138  */
139 #define	TARGIODEBUG		_IOW('C', 9, int)
140 
141 #endif /* _CAM_SCSI_SCSI_TARGETIO_H_ */
142