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
35255570Straszstruct cfiscsi_target {
36255570Strasz	TAILQ_ENTRY(cfiscsi_target)	ct_next;
37255570Strasz	int				ct_luns[CTL_MAX_LUNS];
38255570Strasz	struct cfiscsi_softc		*ct_softc;
39255570Strasz	volatile u_int			ct_refcount;
40255570Strasz	char				ct_name[CTL_ISCSI_NAME_LEN];
41255570Strasz	char				ct_alias[CTL_ISCSI_ALIAS_LEN];
42255570Strasz};
43255570Strasz
44255570Straszstruct cfiscsi_data_wait {
45255570Strasz	TAILQ_ENTRY(cfiscsi_data_wait)	cdw_next;
46255570Strasz	union ctl_io			*cdw_ctl_io;
47255570Strasz	uint32_t			cdw_target_transfer_tag;
48255570Strasz	uint32_t			cdw_initiator_task_tag;
49255570Strasz	int				cdw_sg_index;
50255570Strasz	char				*cdw_sg_addr;
51255570Strasz	size_t				cdw_sg_len;
52255570Strasz};
53255570Strasz
54255570Strasz#define CFISCSI_SESSION_STATE_INVALID		0
55255570Strasz#define CFISCSI_SESSION_STATE_BHS		1
56255570Strasz#define CFISCSI_SESSION_STATE_AHS		2
57255570Strasz#define CFISCSI_SESSION_STATE_HEADER_DIGEST	3
58255570Strasz#define CFISCSI_SESSION_STATE_DATA		4
59255570Strasz#define CFISCSI_SESSION_STATE_DATA_DIGEST	5
60255570Strasz
61255570Straszstruct cfiscsi_session {
62255570Strasz	TAILQ_ENTRY(cfiscsi_session)	cs_next;
63255570Strasz	struct mtx			cs_lock;
64255570Strasz	struct icl_conn			*cs_conn;
65255570Strasz	uint32_t			cs_cmdsn;
66255570Strasz	uint32_t			cs_statsn;
67255570Strasz	uint32_t			cs_target_transfer_tag;
68255570Strasz	volatile u_int			cs_outstanding_ctl_pdus;
69255570Strasz	TAILQ_HEAD(, cfiscsi_data_wait)	cs_waiting_for_data_out;
70255570Strasz	struct cfiscsi_target		*cs_target;
71255570Strasz	struct callout			cs_callout;
72255570Strasz	int				cs_timeout;
73255570Strasz	int				cs_portal_group_tag;
74255570Strasz	struct cv			cs_maintenance_cv;
75255570Strasz	int				cs_terminating;
76255570Strasz	size_t				cs_max_data_segment_length;
77255570Strasz	size_t				cs_max_burst_length;
78255570Strasz	bool				cs_immediate_data;
79255570Strasz	char				cs_initiator_name[CTL_ISCSI_NAME_LEN];
80255570Strasz	char				cs_initiator_addr[CTL_ISCSI_ADDR_LEN];
81255570Strasz	char				cs_initiator_alias[CTL_ISCSI_ALIAS_LEN];
82255570Strasz	unsigned int			cs_id;
83255570Strasz	int				cs_ctl_initid;
84255570Strasz#ifdef ICL_KERNEL_PROXY
85255570Strasz	bool				cs_login_phase;
86255570Strasz	bool				cs_waiting_for_ctld;
87255570Strasz	struct cv			cs_login_cv;
88255570Strasz	struct icl_pdu			*cs_login_pdu;
89255570Strasz#endif
90255570Strasz};
91255570Strasz
92255570Strasz#ifdef ICL_KERNEL_PROXY
93255570Straszstruct icl_listen;
94255570Strasz#endif
95255570Strasz
96255570Straszstruct cfiscsi_softc {
97255570Strasz	struct ctl_frontend		fe;
98255570Strasz	struct mtx			lock;
99255570Strasz	char				port_name[32];
100255570Strasz	int				online;
101255570Strasz	unsigned int			last_session_id;
102255570Strasz	TAILQ_HEAD(, cfiscsi_target)	targets;
103255570Strasz	TAILQ_HEAD(, cfiscsi_session)	sessions;
104255570Strasz	char				ctl_initids[CTL_MAX_INIT_PER_PORT];
105255570Strasz	int				max_initiators;
106255570Strasz#ifdef ICL_KERNEL_PROXY
107255570Strasz	struct icl_listen		*listener;
108255570Strasz	struct cv			accept_cv;
109255570Strasz#endif
110255570Strasz};
111255570Strasz
112255570Strasz#endif /* !CTL_FRONTEND_ISCSI_H */
113