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