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