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 CTL_FRONTEND_ISCSI_H
33255570Strasz#define	CTL_FRONTEND_ISCSI_H
34255570Strasz
35268682Smav#define CFISCSI_TARGET_STATE_INVALID	0
36268682Smav#define CFISCSI_TARGET_STATE_ACTIVE	1
37268682Smav#define CFISCSI_TARGET_STATE_DYING	2
38268682Smav
39255570Straszstruct cfiscsi_target {
40255570Strasz	TAILQ_ENTRY(cfiscsi_target)	ct_next;
41255570Strasz	struct cfiscsi_softc		*ct_softc;
42255570Strasz	volatile u_int			ct_refcount;
43255570Strasz	char				ct_name[CTL_ISCSI_NAME_LEN];
44255570Strasz	char				ct_alias[CTL_ISCSI_ALIAS_LEN];
45279003Smav	uint16_t			ct_tag;
46268682Smav	int				ct_state;
47268682Smav	int				ct_online;
48273319Smav	int				ct_target_id;
49268682Smav	struct ctl_port			ct_port;
50255570Strasz};
51255570Strasz
52255570Straszstruct cfiscsi_data_wait {
53255570Strasz	TAILQ_ENTRY(cfiscsi_data_wait)	cdw_next;
54255570Strasz	union ctl_io			*cdw_ctl_io;
55255570Strasz	uint32_t			cdw_target_transfer_tag;
56255570Strasz	uint32_t			cdw_initiator_task_tag;
57255570Strasz	int				cdw_sg_index;
58255570Strasz	char				*cdw_sg_addr;
59255570Strasz	size_t				cdw_sg_len;
60273310Smav	uint32_t			cdw_r2t_end;
61276613Smav	uint32_t			cdw_datasn;
62255570Strasz};
63255570Strasz
64255570Strasz#define CFISCSI_SESSION_STATE_INVALID		0
65255570Strasz#define CFISCSI_SESSION_STATE_BHS		1
66255570Strasz#define CFISCSI_SESSION_STATE_AHS		2
67255570Strasz#define CFISCSI_SESSION_STATE_HEADER_DIGEST	3
68255570Strasz#define CFISCSI_SESSION_STATE_DATA		4
69255570Strasz#define CFISCSI_SESSION_STATE_DATA_DIGEST	5
70255570Strasz
71255570Straszstruct cfiscsi_session {
72255570Strasz	TAILQ_ENTRY(cfiscsi_session)	cs_next;
73255570Strasz	struct mtx			cs_lock;
74255570Strasz	struct icl_conn			*cs_conn;
75255570Strasz	uint32_t			cs_cmdsn;
76255570Strasz	uint32_t			cs_statsn;
77255570Strasz	uint32_t			cs_target_transfer_tag;
78255570Strasz	volatile u_int			cs_outstanding_ctl_pdus;
79255570Strasz	TAILQ_HEAD(, cfiscsi_data_wait)	cs_waiting_for_data_out;
80255570Strasz	struct cfiscsi_target		*cs_target;
81255570Strasz	struct callout			cs_callout;
82255570Strasz	int				cs_timeout;
83255570Strasz	struct cv			cs_maintenance_cv;
84268258Smav	bool				cs_terminating;
85268691Smav	bool				cs_tasks_aborted;
86255570Strasz	size_t				cs_max_data_segment_length;
87255570Strasz	size_t				cs_max_burst_length;
88255570Strasz	bool				cs_immediate_data;
89255570Strasz	char				cs_initiator_name[CTL_ISCSI_NAME_LEN];
90255570Strasz	char				cs_initiator_addr[CTL_ISCSI_ADDR_LEN];
91255570Strasz	char				cs_initiator_alias[CTL_ISCSI_ALIAS_LEN];
92268684Smav	char				cs_initiator_isid[6];
93268684Smav	char				cs_initiator_id[CTL_ISCSI_NAME_LEN + 5 + 6 + 1];
94255570Strasz	unsigned int			cs_id;
95255570Strasz	int				cs_ctl_initid;
96255570Strasz#ifdef ICL_KERNEL_PROXY
97265513Strasz	struct sockaddr			*cs_initiator_sa;
98265509Strasz	int				cs_portal_id;
99255570Strasz	bool				cs_login_phase;
100255570Strasz	bool				cs_waiting_for_ctld;
101255570Strasz	struct cv			cs_login_cv;
102255570Strasz	struct icl_pdu			*cs_login_pdu;
103255570Strasz#endif
104255570Strasz};
105255570Strasz
106255570Strasz#ifdef ICL_KERNEL_PROXY
107255570Straszstruct icl_listen;
108255570Strasz#endif
109255570Strasz
110255570Straszstruct cfiscsi_softc {
111255570Strasz	struct mtx			lock;
112255570Strasz	char				port_name[32];
113255570Strasz	int				online;
114273319Smav	int				last_target_id;
115255570Strasz	unsigned int			last_session_id;
116255570Strasz	TAILQ_HEAD(, cfiscsi_target)	targets;
117255570Strasz	TAILQ_HEAD(, cfiscsi_session)	sessions;
118275495Smav	struct cv			sessions_cv;
119255570Strasz#ifdef ICL_KERNEL_PROXY
120255570Strasz	struct icl_listen		*listener;
121255570Strasz	struct cv			accept_cv;
122255570Strasz#endif
123255570Strasz};
124255570Strasz
125255570Strasz#endif /* !CTL_FRONTEND_ISCSI_H */
126