xref: /spdk/lib/iscsi/conn.h (revision 04c48172b9879a8824de83c842087d871c433d12)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
5  *   Copyright (c) Intel Corporation.
6  *   All rights reserved.
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  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef SPDK_ISCSI_CONN_H
36 #define SPDK_ISCSI_CONN_H
37 
38 #include <stdbool.h>
39 #include <stdint.h>
40 
41 #include "iscsi/iscsi.h"
42 #include "spdk/queue.h"
43 #include "spdk/event.h"
44 
45 /*
46  * MAX_CONNECTION_PARAMS: The numbers of the params in conn_param_table
47  * MAX_SESSION_PARAMS: The numbers of the params in sess_param_table
48  */
49 #define MAX_CONNECTION_PARAMS 14
50 #define MAX_SESSION_PARAMS 19
51 
52 #define MAX_ADDRBUF 64
53 #define MAX_INITIATOR_ADDR (MAX_ADDRBUF)
54 #define MAX_TARGET_ADDR (MAX_ADDRBUF)
55 
56 #define OWNER_ISCSI_CONN		0x1
57 
58 #define OBJECT_ISCSI_PDU		0x1
59 
60 #define TRACE_GROUP_ISCSI		0x1
61 #define TRACE_READ_FROM_SOCKET_DONE	SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x0)
62 #define TRACE_FLUSH_WRITEBUF_START	SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x1)
63 #define TRACE_FLUSH_WRITEBUF_DONE	SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x2)
64 #define TRACE_READ_PDU			SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x3)
65 #define TRACE_ISCSI_TASK_DONE		SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x4)
66 #define TRACE_ISCSI_TASK_QUEUE		SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x5)
67 #define TRACE_ISCSI_CONN_ACTIVE		SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x6)
68 #define TRACE_ISCSI_CONN_IDLE		SPDK_TPOINT_ID(TRACE_GROUP_ISCSI, 0x7)
69 
70 struct spdk_iscsi_conn {
71 	int				id;
72 	int				is_valid;
73 	int				is_idle;
74 	/*
75 	 * All fields below this point are reinitialized each time the
76 	 *  connection object is allocated.  Make sure to update the
77 	 *  SPDK_ISCSI_CONNECTION_MEMSET() macro if changing which fields
78 	 *  are initialized when allocated.
79 	 */
80 	struct spdk_iscsi_portal		*portal;
81 	uint32_t			lcore;
82 	int				sock;
83 	struct spdk_iscsi_sess	*sess;
84 
85 	enum iscsi_connection_state	state;
86 	int				login_phase;
87 
88 	uint64_t	last_flush;
89 	uint64_t	last_fill;
90 	uint64_t	last_nopin;
91 
92 	/* Timer used to destroy connection after logout if initiator does
93 	 *  not close the connection.
94 	 */
95 	struct spdk_poller *logout_timer;
96 
97 	/* Timer used to wait for connection to close
98 	 */
99 	struct spdk_poller *shutdown_timer;
100 
101 	struct spdk_iscsi_pdu *pdu_in_progress;
102 
103 	TAILQ_HEAD(, spdk_iscsi_pdu) write_pdu_list;
104 	TAILQ_HEAD(, spdk_iscsi_pdu) snack_pdu_list;
105 
106 	int pending_r2t;
107 	struct spdk_iscsi_task *outstanding_r2t_tasks[DEFAULT_MAXR2T];
108 
109 	uint16_t cid;
110 
111 	/* IP address */
112 	char initiator_addr[MAX_INITIATOR_ADDR];
113 	char target_addr[MAX_TARGET_ADDR];
114 
115 	/* Initiator/Target port binds */
116 	char				initiator_name[MAX_INITIATOR_NAME];
117 	struct spdk_scsi_port		*initiator_port;
118 	char				target_short_name[MAX_TARGET_NAME];
119 	struct spdk_scsi_port		*target_port;
120 	struct spdk_iscsi_tgt_node	*target;
121 	struct spdk_scsi_dev		*dev;
122 
123 	/* for fast access */
124 	int header_digest;
125 	int data_digest;
126 	int full_feature;
127 
128 	struct iscsi_param *params;
129 	bool sess_param_state_negotiated[MAX_SESSION_PARAMS];
130 	bool conn_param_state_negotiated[MAX_CONNECTION_PARAMS];
131 	struct iscsi_chap_auth auth;
132 	int authenticated;
133 	int req_auth;
134 	int req_mutual;
135 	uint64_t last_activity_tsc;
136 	uint32_t pending_task_cnt;
137 	uint32_t data_out_cnt;
138 	uint32_t data_in_cnt;
139 	bool pending_activate_event;
140 
141 	int timeout;
142 	uint64_t nopininterval;
143 	bool nop_outstanding;
144 
145 	/*
146 	 * This is the maximum data segment length that iscsi target can send
147 	 *  to the initiator on this connection.  Not to be confused with the
148 	 *  maximum data segment length that initiators can send to iscsi target, which
149 	 *  is statically defined as SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH.
150 	 */
151 	int MaxRecvDataSegmentLength;
152 
153 	uint32_t StatSN;
154 	uint32_t exp_statsn;
155 	uint32_t ttt; /* target transfer tag*/
156 	char *partial_text_parameter;
157 
158 	STAILQ_ENTRY(spdk_iscsi_conn) link;
159 	struct spdk_poller	*poller;
160 	TAILQ_HEAD(queued_r2t_tasks, spdk_iscsi_task)	queued_r2t_tasks;
161 	TAILQ_HEAD(active_r2t_tasks, spdk_iscsi_task)	active_r2t_tasks;
162 	TAILQ_HEAD(queued_datain_tasks, spdk_iscsi_task)	queued_datain_tasks;
163 };
164 
165 int spdk_initialize_iscsi_conns(void);
166 void spdk_shutdown_iscsi_conns(void);
167 
168 int spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, int sock);
169 void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn);
170 void spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn);
171 int spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn,
172 			  const char *conn_match, int drop_all);
173 void spdk_iscsi_conn_set_min_per_core(int count);
174 void spdk_iscsi_set_min_conn_idle_interval(int interval_in_us);
175 
176 int spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len,
177 			      void *buf);
178 
179 #endif /* SPDK_ISCSI_CONN_H */
180