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