xref: /freebsd/sys/dev/iscsi/iscsi.h (revision 0957b409)
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_H
35 #define	ISCSI_H
36 
37 struct iscsi_softc;
38 struct icl_conn;
39 
40 #define	ISCSI_NAME_LEN		224	/* 223 bytes, by RFC 3720, + '\0' */
41 #define	ISCSI_ADDR_LEN		47	/* INET6_ADDRSTRLEN + '\0' */
42 #define	ISCSI_SECRET_LEN	17	/* 16 + '\0' */
43 
44 struct iscsi_outstanding {
45 	TAILQ_ENTRY(iscsi_outstanding)	io_next;
46 	union ccb			*io_ccb;
47 	size_t				io_received;
48 	uint32_t			io_initiator_task_tag;
49 	uint32_t			io_datasn;
50 	void				*io_icl_prv;
51 };
52 
53 struct iscsi_session {
54 	TAILQ_ENTRY(iscsi_session)	is_next;
55 
56 	struct icl_conn			*is_conn;
57 	struct mtx			is_lock;
58 
59 	uint32_t			is_statsn;
60 	uint32_t			is_cmdsn;
61 	uint32_t			is_expcmdsn;
62 	uint32_t			is_maxcmdsn;
63 	uint32_t			is_initiator_task_tag;
64 	int				is_header_digest;
65 	int				is_data_digest;
66 	int				is_initial_r2t;
67 	int				is_max_burst_length;
68 	int				is_first_burst_length;
69 	uint8_t				is_isid[6];
70 	uint16_t			is_tsih;
71 	bool				is_immediate_data;
72 	int				is_max_recv_data_segment_length;
73 	int				is_max_send_data_segment_length;
74 	char				is_target_alias[ISCSI_ALIAS_LEN];
75 
76 	TAILQ_HEAD(, iscsi_outstanding)	is_outstanding;
77 	STAILQ_HEAD(, icl_pdu)		is_postponed;
78 
79 	struct callout			is_callout;
80 	unsigned int			is_timeout;
81 
82 	/*
83 	 * XXX: This could be rewritten using a single variable,
84 	 * 	but somehow it results in uglier code.
85 	 */
86 	/*
87 	 * We're waiting for iscsid(8); after iscsid_timeout
88 	 * expires, kernel will wake up an iscsid(8) to handle
89 	 * the session.
90 	 */
91 	bool				is_waiting_for_iscsid;
92 
93 	/*
94 	 * Some iscsid(8) instance is handling the session;
95 	 * after login_timeout expires, kernel will wake up
96 	 * another iscsid(8) to handle the session.
97 	 */
98 	bool				is_login_phase;
99 
100 	/*
101 	 * We're in the process of removing the iSCSI session.
102 	 */
103 	bool				is_terminating;
104 
105 	/*
106 	 * We're waiting for the maintenance thread to do some
107 	 * reconnection tasks.
108 	 */
109 	bool				is_reconnecting;
110 
111 	bool				is_connected;
112 
113 	struct cam_devq			*is_devq;
114 	struct cam_sim			*is_sim;
115 	struct cam_path			*is_path;
116 	struct cv			is_maintenance_cv;
117 	struct iscsi_softc		*is_softc;
118 	unsigned int			is_id;
119 	struct iscsi_session_conf	is_conf;
120 	bool				is_simq_frozen;
121 
122 	char				is_reason[ISCSI_REASON_LEN];
123 
124 #ifdef ICL_KERNEL_PROXY
125 	struct cv			is_login_cv;
126 	struct icl_pdu			*is_login_pdu;
127 #endif
128 };
129 
130 struct iscsi_softc {
131 	device_t			sc_dev;
132 	struct sx			sc_lock;
133 	struct cdev			*sc_cdev;
134 	TAILQ_HEAD(, iscsi_session)	sc_sessions;
135 	struct cv			sc_cv;
136 	unsigned int			sc_last_session_id;
137 	eventhandler_tag		sc_shutdown_pre_eh;
138 	eventhandler_tag		sc_shutdown_post_eh;
139 };
140 
141 #endif /* !ISCSI_H */
142