1255570Strasz/*-
2255570Strasz * Copyright (c) 2012 The FreeBSD Foundation
3255570Strasz * All rights reserved.
4255570Strasz *
5255570Strasz * This software was developed by Edward Tomasz Napierala under sponsorship
6255570Strasz * from the FreeBSD Foundation.
7255570Strasz *
8255570Strasz * Redistribution and use in source and binary forms, with or without
9255570Strasz * modification, are permitted provided that the following conditions
10255570Strasz * are met:
11255570Strasz * 1. Redistributions of source code must retain the above copyright
12255570Strasz *    notice, this list of conditions and the following disclaimer.
13255570Strasz * 2. Redistributions in binary form must reproduce the above copyright
14255570Strasz *    notice, this list of conditions and the following disclaimer in the
15255570Strasz *    documentation and/or other materials provided with the distribution.
16255570Strasz *
17255570Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18255570Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19255570Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20255570Strasz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21255570Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22255570Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23255570Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24255570Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25255570Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26255570Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27255570Strasz * SUCH DAMAGE.
28255570Strasz *
29255570Strasz * $FreeBSD$
30255570Strasz */
31255570Strasz
32255570Strasz#ifndef ISCSI_H
33255570Strasz#define	ISCSI_H
34255570Strasz
35255570Straszstruct iscsi_softc;
36255570Straszstruct icl_conn;
37255570Strasz
38255570Strasz#define	ISCSI_NAME_LEN		224	/* 223 bytes, by RFC 3720, + '\0' */
39255570Strasz#define	ISCSI_ADDR_LEN		47	/* INET6_ADDRSTRLEN + '\0' */
40255570Strasz#define	ISCSI_SECRET_LEN	17	/* 16 + '\0' */
41255570Strasz
42255570Straszstruct iscsi_outstanding {
43255570Strasz	TAILQ_ENTRY(iscsi_outstanding)	io_next;
44255570Strasz	union ccb			*io_ccb;
45255570Strasz	size_t				io_received;
46255570Strasz	uint32_t			io_initiator_task_tag;
47255570Strasz	uint32_t			io_datasn;
48278397Strasz	void				*io_icl_prv;
49255570Strasz};
50255570Strasz
51255570Straszstruct iscsi_session {
52255570Strasz	TAILQ_ENTRY(iscsi_session)	is_next;
53255570Strasz
54255570Strasz	struct icl_conn			*is_conn;
55255570Strasz	struct mtx			is_lock;
56255570Strasz
57255570Strasz	uint32_t			is_statsn;
58255570Strasz	uint32_t			is_cmdsn;
59255570Strasz	uint32_t			is_expcmdsn;
60255570Strasz	uint32_t			is_maxcmdsn;
61255570Strasz	uint32_t			is_initiator_task_tag;
62255570Strasz	int				is_header_digest;
63255570Strasz	int				is_data_digest;
64255570Strasz	int				is_initial_r2t;
65255570Strasz	size_t				is_max_burst_length;
66255570Strasz	size_t				is_first_burst_length;
67255570Strasz	uint8_t				is_isid[6];
68268326Smav	uint16_t			is_tsih;
69255570Strasz	bool				is_immediate_data;
70255570Strasz	size_t				is_max_data_segment_length;
71255570Strasz	char				is_target_alias[ISCSI_ALIAS_LEN];
72255570Strasz
73255570Strasz	TAILQ_HEAD(, iscsi_outstanding)	is_outstanding;
74264109Strasz	STAILQ_HEAD(, icl_pdu)		is_postponed;
75255570Strasz
76255570Strasz	struct callout			is_callout;
77255570Strasz	unsigned int			is_timeout;
78255570Strasz
79255570Strasz	/*
80255570Strasz	 * XXX: This could be rewritten using a single variable,
81255570Strasz	 * 	but somehow it results in uglier code.
82255570Strasz	 */
83255570Strasz	/*
84255570Strasz	 * We're waiting for iscsid(8); after iscsid_timeout
85255570Strasz	 * expires, kernel will wake up an iscsid(8) to handle
86255570Strasz	 * the session.
87255570Strasz	 */
88255570Strasz	bool				is_waiting_for_iscsid;
89255570Strasz
90255570Strasz	/*
91255570Strasz	 * Some iscsid(8) instance is handling the session;
92255570Strasz	 * after login_timeout expires, kernel will wake up
93255570Strasz	 * another iscsid(8) to handle the session.
94255570Strasz	 */
95255570Strasz	bool				is_login_phase;
96255570Strasz
97255570Strasz	/*
98255570Strasz	 * We're in the process of removing the iSCSI session.
99255570Strasz	 */
100255570Strasz	bool				is_terminating;
101255570Strasz
102255570Strasz	/*
103255570Strasz	 * We're waiting for the maintenance thread to do some
104255570Strasz	 * reconnection tasks.
105255570Strasz	 */
106255570Strasz	bool				is_reconnecting;
107255570Strasz
108255570Strasz	bool				is_connected;
109255570Strasz
110255570Strasz	struct cam_devq			*is_devq;
111255570Strasz	struct cam_sim			*is_sim;
112255570Strasz	struct cam_path			*is_path;
113255570Strasz	struct cv			is_maintenance_cv;
114255570Strasz	struct iscsi_softc		*is_softc;
115255570Strasz	unsigned int			is_id;
116255570Strasz	struct iscsi_session_conf	is_conf;
117255570Strasz	bool				is_simq_frozen;
118255570Strasz
119255570Strasz	char				is_reason[ISCSI_REASON_LEN];
120255570Strasz
121255570Strasz#ifdef ICL_KERNEL_PROXY
122295476Strasz	struct cv			is_login_cv;
123255570Strasz	struct icl_pdu			*is_login_pdu;
124255570Strasz#endif
125255570Strasz};
126255570Strasz
127255570Straszstruct iscsi_softc {
128255570Strasz	device_t			sc_dev;
129255570Strasz	struct sx			sc_lock;
130255570Strasz	struct cdev			*sc_cdev;
131255570Strasz	TAILQ_HEAD(, iscsi_session)	sc_sessions;
132255570Strasz	struct cv			sc_cv;
133255570Strasz	unsigned int			sc_last_session_id;
134293659Ssmh	eventhandler_tag		sc_shutdown_pre_eh;
135293659Ssmh	eventhandler_tag		sc_shutdown_post_eh;
136255570Strasz};
137255570Strasz
138255570Strasz#endif /* !ISCSI_H */
139