xref: /freebsd/sys/dev/iscsi/iscsi_ioctl.h (revision 09127a36371d5f5ac109ad1063e7fe53ee9bf356)
1 /*-
2  * Copyright (c) 2012 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Edward Tomasz Napierala under sponsorship
6  * from the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #ifndef ISCSI_IOCTL_H
33 #define	ISCSI_IOCTL_H
34 
35 #ifdef ICL_KERNEL_PROXY
36 #include <sys/socket.h>
37 #endif
38 
39 #define	ISCSI_PATH		"/dev/iscsi"
40 #define	ISCSI_MAX_DATA_SEGMENT_LENGTH	(128 * 1024)
41 
42 #define	ISCSI_NAME_LEN		224	/* 223 bytes, by RFC 3720, + '\0' */
43 #define	ISCSI_ADDR_LEN		47	/* INET6_ADDRSTRLEN + '\0' */
44 #define	ISCSI_ALIAS_LEN		256	/* XXX: Where did it come from? */
45 #define	ISCSI_SECRET_LEN	17	/* 16 + '\0' */
46 #define	ISCSI_REASON_LEN	64
47 
48 #define	ISCSI_DIGEST_NONE	0
49 #define	ISCSI_DIGEST_CRC32C	1
50 
51 /*
52  * Session configuration, set when adding the session.
53  */
54 struct iscsi_session_conf {
55 	char 		isc_initiator[ISCSI_NAME_LEN];
56 	char		isc_initiator_addr[ISCSI_ADDR_LEN];
57 	char		isc_initiator_alias[ISCSI_ALIAS_LEN];
58 	char 		isc_target[ISCSI_NAME_LEN];
59 	char		isc_target_addr[ISCSI_ADDR_LEN];
60 	char		isc_user[ISCSI_NAME_LEN];
61 	char		isc_secret[ISCSI_SECRET_LEN];
62 	char		isc_mutual_user[ISCSI_NAME_LEN];
63 	char		isc_mutual_secret[ISCSI_SECRET_LEN];
64 	int		isc_discovery;
65 	int		isc_header_digest;
66 	int		isc_data_digest;
67 	int		isc_iser;
68 	int		isc_spare[4];
69 };
70 
71 /*
72  * Session state, negotiated by iscsid(8) and queried by iscsictl(8).
73  */
74 struct iscsi_session_state {
75 	struct iscsi_session_conf	iss_conf;
76 	unsigned int	iss_id;
77 	char		iss_target_alias[ISCSI_ALIAS_LEN];
78 	int		iss_header_digest;
79 	int		iss_data_digest;
80 	int		iss_max_data_segment_length;
81 	int		iss_immediate_data;
82 	int		iss_connected;
83 	char		iss_reason[ISCSI_REASON_LEN];
84 	int		iss_spare[4];
85 };
86 
87 /*
88  * For use with iscsid(8).
89  */
90 
91 struct iscsi_daemon_request {
92 	unsigned int			idr_session_id;
93 	struct iscsi_session_conf	idr_conf;
94 	uint8_t				idr_spare_isid[6];
95 	uint16_t			idr_spare_tsih;
96 	uint16_t			idr_spare_cid;
97 	int				idr_spare[4];
98 };
99 
100 struct iscsi_daemon_handoff {
101 	unsigned int			idh_session_id;
102 	int				idh_socket;
103 	char				idh_target_alias[ISCSI_ALIAS_LEN];
104 	uint8_t				idh_isid[6];
105 	uint16_t			idr_spare_tsih;
106 	uint16_t			idr_spare_cid;
107 	uint32_t			idh_statsn;
108 	int				idh_header_digest;
109 	int				idh_data_digest;
110 	int				idh_initial_r2t;
111 	int				idh_immediate_data;
112 	size_t				idh_max_data_segment_length;
113 	size_t				idh_max_burst_length;
114 	size_t				idh_first_burst_length;
115 	int				idh_spare[4];
116 };
117 
118 struct iscsi_daemon_fail {
119 	unsigned int			idf_session_id;
120 	char				idf_reason[ISCSI_REASON_LEN];
121 	int				idf_spare[4];
122 };
123 
124 #define	ISCSIDWAIT	_IOR('I', 0x01, struct iscsi_daemon_request)
125 #define	ISCSIDHANDOFF	_IOW('I', 0x02, struct iscsi_daemon_handoff)
126 #define	ISCSIDFAIL	_IOW('I', 0x03, struct iscsi_daemon_fail)
127 
128 #ifdef ICL_KERNEL_PROXY
129 
130 /*
131  * When ICL_KERNEL_PROXY is not defined, the iscsid(8) is responsible
132  * for creating the socket, connecting, performing Login Phase using
133  * socked in the usual userspace way, and then passing the socket file
134  * descriptor to the kernel part using ISCSIDHANDOFF.
135  *
136  * When ICL_KERNEL_PROXY is defined, the iscsid(8) creates the session
137  * using ISCSICONNECT, performs Login Phase using ISCSISEND/ISCSIRECEIVE
138  * instead of read(2)/write(2), and then calls ISCSIDHANDOFF with
139  * idh_socket set to 0.
140  *
141  * The purpose of ICL_KERNEL_PROXY is to workaround the fact that,
142  * at this time, it's not possible to do iWARP (RDMA) in userspace.
143  */
144 
145 struct iscsi_daemon_connect {
146 	int				idc_session_id;
147 	int				idc_iser;
148 	int				idc_domain;
149 	int				idc_socktype;
150 	int				idc_protocol;
151 	struct sockaddr			*idc_from_addr;
152 	socklen_t			idc_from_addrlen;
153 	struct sockaddr			*idc_to_addr;
154 	socklen_t			idc_to_addrlen;
155 	int				idc_spare[4];
156 };
157 
158 struct iscsi_daemon_send {
159 	int				ids_session_id;
160 	void				*ids_bhs;
161 	size_t				ids_spare;
162 	void				*ids_spare2;
163 	size_t				ids_data_segment_len;
164 	void				*ids_data_segment;
165 	int				ids_spare[4];
166 };
167 
168 struct iscsi_daemon_receive {
169 	int				idr_session_id;
170 	void				*idr_bhs;
171 	size_t				idr_spare;
172 	void				*idr_spare2;
173 	size_t				idr_data_segment_len;
174 	void				*idr_data_segment;
175 	int				idr_spare[4];
176 };
177 
178 struct iscsi_daemon_close {
179 	int				idc_session_id;
180 	int				idc_spare[4];
181 };
182 
183 #define	ISCSIDCONNECT	_IOWR('I', 0x04, struct iscsi_daemon_connect)
184 #define	ISCSIDSEND	_IOWR('I', 0x05, struct iscsi_daemon_send)
185 #define	ISCSIDRECEIVE	_IOWR('I', 0x06, struct iscsi_daemon_receive)
186 #define	ISCSIDCLOSE	_IOWR('I', 0x07, struct iscsi_daemon_close)
187 
188 #endif /* ICL_KERNEL_PROXY */
189 
190 /*
191  * For use with iscsictl(8).
192  */
193 
194 struct iscsi_session_add {
195 	struct iscsi_session_conf	isa_conf;
196 	int				isa_spare[4];
197 };
198 
199 struct iscsi_session_remove {
200 	unsigned int			isr_session_id;
201 	struct iscsi_session_conf	isr_conf;
202 	int				isr_spare[4];
203 };
204 
205 struct iscsi_session_list {
206 	unsigned int			isl_nentries;
207 	struct iscsi_session_state	*isl_pstates;
208 	int				isl_spare[4];
209 };
210 
211 #define	ISCSISADD	_IOW('I', 0x11, struct iscsi_session_add)
212 #define	ISCSISREMOVE	_IOW('I', 0x12, struct iscsi_session_remove)
213 #define	ISCSISLIST	_IOWR('I', 0x13, struct iscsi_session_list)
214 
215 #endif /* !ISCSI_IOCTL_H */
216