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