ctl_frontend_iscsi.h revision 276613
1178476Sjb/*-
2178476Sjb * Copyright (c) 2012 The FreeBSD Foundation
3178476Sjb * All rights reserved.
4178476Sjb *
5178476Sjb * This software was developed by Edward Tomasz Napierala under sponsorship
6178476Sjb * from the FreeBSD Foundation.
7178476Sjb *
8178476Sjb * Redistribution and use in source and binary forms, with or without
9178476Sjb * modification, are permitted provided that the following conditions
10178476Sjb * are met:
11178476Sjb * 1. Redistributions of source code must retain the above copyright
12178476Sjb *    notice, this list of conditions and the following disclaimer.
13178476Sjb * 2. Redistributions in binary form must reproduce the above copyright
14178476Sjb *    notice, this list of conditions and the following disclaimer in the
15178476Sjb *    documentation and/or other materials provided with the distribution.
16178476Sjb *
17178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20178476Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21178476Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22178476Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23178476Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24178476Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25178476Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26178476Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27178476Sjb * SUCH DAMAGE.
28178476Sjb *
29178476Sjb * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.h 276613 2015-01-03 13:08:08Z mav $
30178476Sjb */
31178476Sjb
32178476Sjb#ifndef CTL_FRONTEND_ISCSI_H
33178476Sjb#define	CTL_FRONTEND_ISCSI_H
34178476Sjb
35178476Sjb#define CFISCSI_TARGET_STATE_INVALID	0
36178476Sjb#define CFISCSI_TARGET_STATE_ACTIVE	1
37178476Sjb#define CFISCSI_TARGET_STATE_DYING	2
38178476Sjb
39178476Sjbstruct cfiscsi_target {
40178476Sjb	TAILQ_ENTRY(cfiscsi_target)	ct_next;
41178476Sjb	uint32_t			ct_luns[CTL_MAX_LUNS];
42178476Sjb	struct cfiscsi_softc		*ct_softc;
43178476Sjb	volatile u_int			ct_refcount;
44178476Sjb	char				ct_name[CTL_ISCSI_NAME_LEN];
45178476Sjb	char				ct_alias[CTL_ISCSI_ALIAS_LEN];
46178476Sjb	int				ct_state;
47178476Sjb	int				ct_online;
48178476Sjb	int				ct_target_id;
49178476Sjb	struct ctl_port			ct_port;
50178476Sjb};
51178476Sjb
52178476Sjbstruct cfiscsi_data_wait {
53178476Sjb	TAILQ_ENTRY(cfiscsi_data_wait)	cdw_next;
54178476Sjb	union ctl_io			*cdw_ctl_io;
55178476Sjb	uint32_t			cdw_target_transfer_tag;
56178476Sjb	uint32_t			cdw_initiator_task_tag;
57178476Sjb	int				cdw_sg_index;
58178476Sjb	char				*cdw_sg_addr;
59178476Sjb	size_t				cdw_sg_len;
60178476Sjb	uint32_t			cdw_r2t_end;
61178476Sjb	uint32_t			cdw_datasn;
62178476Sjb};
63178476Sjb
64178476Sjb#define CFISCSI_SESSION_STATE_INVALID		0
65178476Sjb#define CFISCSI_SESSION_STATE_BHS		1
66178476Sjb#define CFISCSI_SESSION_STATE_AHS		2
67178476Sjb#define CFISCSI_SESSION_STATE_HEADER_DIGEST	3
68178476Sjb#define CFISCSI_SESSION_STATE_DATA		4
69178476Sjb#define CFISCSI_SESSION_STATE_DATA_DIGEST	5
70178476Sjb
71178476Sjbstruct cfiscsi_session {
72178476Sjb	TAILQ_ENTRY(cfiscsi_session)	cs_next;
73178476Sjb	struct mtx			cs_lock;
74178476Sjb	struct icl_conn			*cs_conn;
75178476Sjb	uint32_t			cs_cmdsn;
76178476Sjb	uint32_t			cs_statsn;
77178476Sjb	uint32_t			cs_target_transfer_tag;
78178476Sjb	volatile u_int			cs_outstanding_ctl_pdus;
79178476Sjb	TAILQ_HEAD(, cfiscsi_data_wait)	cs_waiting_for_data_out;
80178476Sjb	struct cfiscsi_target		*cs_target;
81178476Sjb	struct callout			cs_callout;
82178476Sjb	int				cs_timeout;
83178476Sjb	int				cs_portal_group_tag;
84178476Sjb	struct cv			cs_maintenance_cv;
85178476Sjb	bool				cs_terminating;
86178476Sjb	bool				cs_tasks_aborted;
87178476Sjb	size_t				cs_max_data_segment_length;
88	size_t				cs_max_burst_length;
89	bool				cs_immediate_data;
90	char				cs_initiator_name[CTL_ISCSI_NAME_LEN];
91	char				cs_initiator_addr[CTL_ISCSI_ADDR_LEN];
92	char				cs_initiator_alias[CTL_ISCSI_ALIAS_LEN];
93	char				cs_initiator_isid[6];
94	char				cs_initiator_id[CTL_ISCSI_NAME_LEN + 5 + 6 + 1];
95	unsigned int			cs_id;
96	int				cs_ctl_initid;
97#ifdef ICL_KERNEL_PROXY
98	struct sockaddr			*cs_initiator_sa;
99	int				cs_portal_id;
100	bool				cs_login_phase;
101	bool				cs_waiting_for_ctld;
102	struct cv			cs_login_cv;
103	struct icl_pdu			*cs_login_pdu;
104#endif
105};
106
107#ifdef ICL_KERNEL_PROXY
108struct icl_listen;
109#endif
110
111struct cfiscsi_softc {
112	struct mtx			lock;
113	char				port_name[32];
114	int				online;
115	int				last_target_id;
116	unsigned int			last_session_id;
117	TAILQ_HEAD(, cfiscsi_target)	targets;
118	TAILQ_HEAD(, cfiscsi_session)	sessions;
119	struct cv			sessions_cv;
120#ifdef ICL_KERNEL_PROXY
121	struct icl_listen		*listener;
122	struct cv			accept_cv;
123#endif
124};
125
126#endif /* !CTL_FRONTEND_ISCSI_H */
127