xref: /freebsd/sys/cam/ctl/ctl_frontend_iscsi.h (revision 0957b409)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2012 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * This software was developed by Edward Tomasz Napierala under sponsorship
8  * from the FreeBSD Foundation.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef CTL_FRONTEND_ISCSI_H
35 #define	CTL_FRONTEND_ISCSI_H
36 
37 #define CFISCSI_TARGET_STATE_INVALID	0
38 #define CFISCSI_TARGET_STATE_ACTIVE	1
39 #define CFISCSI_TARGET_STATE_DYING	2
40 
41 struct cfiscsi_target {
42 	TAILQ_ENTRY(cfiscsi_target)	ct_next;
43 	struct cfiscsi_softc		*ct_softc;
44 	volatile u_int			ct_refcount;
45 	char				ct_name[CTL_ISCSI_NAME_LEN];
46 	char				ct_alias[CTL_ISCSI_ALIAS_LEN];
47 	uint16_t			ct_tag;
48 	int				ct_state;
49 	int				ct_online;
50 	int				ct_target_id;
51 	struct ctl_port			ct_port;
52 };
53 
54 struct cfiscsi_data_wait {
55 	TAILQ_ENTRY(cfiscsi_data_wait)	cdw_next;
56 	union ctl_io			*cdw_ctl_io;
57 	uint32_t			cdw_target_transfer_tag;
58 	uint32_t			cdw_initiator_task_tag;
59 	int				cdw_sg_index;
60 	char				*cdw_sg_addr;
61 	size_t				cdw_sg_len;
62 	uint32_t			cdw_r2t_end;
63 	uint32_t			cdw_datasn;
64 	void				*cdw_icl_prv;
65 };
66 
67 #define CFISCSI_SESSION_STATE_INVALID		0
68 #define CFISCSI_SESSION_STATE_BHS		1
69 #define CFISCSI_SESSION_STATE_AHS		2
70 #define CFISCSI_SESSION_STATE_HEADER_DIGEST	3
71 #define CFISCSI_SESSION_STATE_DATA		4
72 #define CFISCSI_SESSION_STATE_DATA_DIGEST	5
73 
74 struct cfiscsi_session {
75 	TAILQ_ENTRY(cfiscsi_session)	cs_next;
76 	struct mtx			cs_lock;
77 	struct icl_conn			*cs_conn;
78 	uint32_t			cs_cmdsn;
79 	uint32_t			cs_statsn;
80 	uint32_t			cs_target_transfer_tag;
81 	volatile u_int			cs_outstanding_ctl_pdus;
82 	TAILQ_HEAD(, cfiscsi_data_wait)	cs_waiting_for_data_out;
83 	struct cfiscsi_target		*cs_target;
84 	struct callout			cs_callout;
85 	int				cs_timeout;
86 	struct cv			cs_maintenance_cv;
87 	bool				cs_terminating;
88 	bool				cs_handoff_in_progress;
89 	bool				cs_tasks_aborted;
90 	int				cs_max_recv_data_segment_length;
91 	int				cs_max_send_data_segment_length;
92 	int				cs_max_burst_length;
93 	int				cs_first_burst_length;
94 	bool				cs_immediate_data;
95 	char				cs_initiator_name[CTL_ISCSI_NAME_LEN];
96 	char				cs_initiator_addr[CTL_ISCSI_ADDR_LEN];
97 	char				cs_initiator_alias[CTL_ISCSI_ALIAS_LEN];
98 	char				cs_initiator_isid[6];
99 	char				cs_initiator_id[CTL_ISCSI_NAME_LEN + 5 + 6 + 1];
100 	unsigned int			cs_id;
101 	int				cs_ctl_initid;
102 #ifdef ICL_KERNEL_PROXY
103 	struct sockaddr			*cs_initiator_sa;
104 	int				cs_portal_id;
105 	bool				cs_login_phase;
106 	bool				cs_waiting_for_ctld;
107 	struct cv			cs_login_cv;
108 	struct icl_pdu			*cs_login_pdu;
109 #endif
110 };
111 
112 #ifdef ICL_KERNEL_PROXY
113 struct icl_listen;
114 #endif
115 
116 struct cfiscsi_softc {
117 	struct mtx			lock;
118 	char				port_name[32];
119 	int				online;
120 	int				last_target_id;
121 	unsigned int			last_session_id;
122 	TAILQ_HEAD(, cfiscsi_target)	targets;
123 	TAILQ_HEAD(, cfiscsi_session)	sessions;
124 	struct cv			sessions_cv;
125 #ifdef ICL_KERNEL_PROXY
126 	struct icl_listen		*listener;
127 	struct cv			accept_cv;
128 #endif
129 };
130 
131 #endif /* !CTL_FRONTEND_ISCSI_H */
132