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