2 * iSCSI lib definitions
4 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2004 - 2006 Mike Christie
6 * Copyright (C) 2004 - 2005 Dmitry Yusupov
7 * Copyright (C) 2004 - 2005 Alex Aizman
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <linux/types.h>
27 #include <linux/mutex.h>
28 #include <linux/timer.h>
29 #include <linux/workqueue.h>
30 #include <scsi/iscsi_proto.h>
31 #include <scsi/iscsi_if.h>
33 struct scsi_transport_template;
38 struct iscsi_transport;
39 struct iscsi_cls_session;
40 struct iscsi_cls_conn;
44 /* #define DEBUG_SCSI */
46 #define debug_scsi(fmt...) printk(KERN_INFO "iscsi: " fmt)
48 #define debug_scsi(fmt...)
51 #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* must be power of 2 */
52 #define ISCSI_MGMT_CMDS_MAX 16 /* must be power of 2 */
54 #define ISCSI_MGMT_ITT_OFFSET 0xa00
56 #define ISCSI_DEF_CMD_PER_LUN 32
57 #define ISCSI_MAX_CMD_PER_LUN 128
59 /* Task Mgmt states */
69 /* Connection suspend "bit" */
70 #define ISCSI_SUSPEND_BIT 1
72 #define ISCSI_ITT_MASK (0xfff)
73 #define ISCSI_CID_SHIFT 12
74 #define ISCSI_CID_MASK (0xffff << ISCSI_CID_SHIFT)
75 #define ISCSI_AGE_SHIFT 28
76 #define ISCSI_AGE_MASK (0xf << ISCSI_AGE_SHIFT)
78 #define ISCSI_ADDRESS_BUF_LEN 64
81 ISCSI_DIGEST_SIZE = sizeof(__u32),
84 struct iscsi_mgmt_task {
86 * Becuae LLDs allocate their hdr differently, this is a pointer to
87 * that storage. It must be setup at session creation time.
89 struct iscsi_hdr *hdr;
90 char *data; /* mgmt payload */
91 unsigned data_count; /* counts data to be sent */
92 uint32_t itt; /* this ITT */
93 void *dd_data; /* driver/transport data */
94 struct list_head running;
103 struct iscsi_cmd_task {
105 * Becuae LLDs allocate their hdr differently, this is a pointer to
106 * that storage. It must be setup at session creation time.
108 struct iscsi_cmd *hdr;
109 int itt; /* this ITT */
111 uint32_t unsol_datasn;
112 unsigned imm_count; /* imm-data (bytes) */
113 unsigned unsol_count; /* unsolicited (bytes)*/
114 /* offset in unsolicited stream (bytes); */
115 unsigned unsol_offset;
116 unsigned data_count; /* remaining Data-Out */
117 struct scsi_cmnd *sc; /* associated SCSI cmd*/
118 struct iscsi_conn *conn; /* used connection */
120 /* state set/tested under session->lock */
123 struct list_head running; /* running cmd list */
124 void *dd_data; /* driver/transport data */
128 struct iscsi_cls_conn *cls_conn; /* ptr to class connection */
129 void *dd_data; /* iscsi_transport data */
130 struct iscsi_session *session; /* parent session */
132 * LLDs should set this lock. It protects the transport recv
137 * conn_stop() flag: stop to recover, stop to terminate
141 /* iSCSI connection-wide sequencing */
146 int c_stage; /* connection state */
148 * Preallocated buffer for pdus that have data but do not
149 * originate from scsi-ml. We never have two pdus using the
150 * buffer at the same time. It is only allocated to
151 * the default max recv size because the pdus we support
152 * should always fit in this buffer
155 struct iscsi_mgmt_task *login_mtask; /* mtask used for login/text */
156 struct iscsi_mgmt_task *mtask; /* xmit mtask in progress */
157 struct iscsi_cmd_task *ctask; /* xmit ctask in progress */
160 struct list_head mgmtqueue; /* mgmt (control) xmit queue */
161 struct list_head mgmt_run_list; /* list of control tasks */
162 struct list_head xmitqueue; /* data-path cmd queue */
163 struct list_head run_list; /* list of cmds in progress */
164 struct list_head requeue; /* tasks needing another run */
165 struct work_struct xmitwork; /* per-conn. xmit workqueue */
166 unsigned long suspend_tx; /* suspend Tx */
167 unsigned long suspend_rx; /* suspend Rx */
170 wait_queue_head_t ehwait; /* used in eh_abort() */
171 struct iscsi_tm tmhdr;
172 struct timer_list tmf_timer;
173 int tmf_state; /* see TMF_INITIAL, etc.*/
175 /* negotiated params */
176 unsigned max_recv_dlength; /* initiator_max_recv_dsl*/
177 unsigned max_xmit_dlength; /* target_max_recv_dsl */
182 /* values userspace uses to id a conn */
184 char *persistent_address;
185 /* remote portal currently connected to */
187 char portal_address[ISCSI_ADDRESS_BUF_LEN];
190 char local_address[ISCSI_ADDRESS_BUF_LEN];
193 uint64_t txdata_octets;
194 uint64_t rxdata_octets;
195 uint32_t scsicmd_pdus_cnt;
196 uint32_t dataout_pdus_cnt;
197 uint32_t scsirsp_pdus_cnt;
198 uint32_t datain_pdus_cnt;
199 uint32_t r2t_pdus_cnt;
200 uint32_t tmfcmd_pdus_cnt;
201 int32_t tmfrsp_pdus_cnt;
203 /* custom statistics */
204 uint32_t eh_abort_cnt;
208 struct kfifo *queue; /* FIFO Queue */
209 void **pool; /* Pool of elements */
210 int max; /* Max number of elements */
213 struct iscsi_session {
215 * Syncs up the scsi eh thread with the iscsi eh thread when sending
216 * task management functions. This must be taken before the session
219 struct mutex eh_mutex;
221 /* iSCSI session-wide sequencing */
226 /* This tracks the reqs queued into the initiator */
227 uint32_t queued_cmdsn;
233 unsigned first_burst;
238 int dataseq_inorder_en;
248 /* hw address or netdev iscsi connection is bound to */
252 struct iscsi_transport *tt;
253 struct Scsi_Host *host;
254 struct iscsi_conn *leadconn; /* leading connection */
255 spinlock_t lock; /* protects session state, *
256 * sequence numbers, *
257 * session resources: *
261 int state; /* session state */
262 int age; /* counts session re-opens */
264 int cmds_max; /* size of cmds array */
265 struct iscsi_cmd_task **cmds; /* Original Cmds arr */
266 struct iscsi_queue cmdpool; /* PDU's pool */
267 int mgmtpool_max; /* size of mgmt array */
268 struct iscsi_mgmt_task **mgmt_cmds; /* Original mgmt arr */
269 struct iscsi_queue mgmtpool; /* Mgmt PDU's pool */
275 extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth);
276 extern int iscsi_eh_abort(struct scsi_cmnd *sc);
277 extern int iscsi_eh_host_reset(struct scsi_cmnd *sc);
278 extern int iscsi_eh_device_reset(struct scsi_cmnd *sc);
279 extern int iscsi_queuecommand(struct scsi_cmnd *sc,
280 void (*done)(struct scsi_cmnd *));
284 * iSCSI host helpers.
286 extern int iscsi_host_set_param(struct Scsi_Host *shost,
287 enum iscsi_host_param param, char *buf,
289 extern int iscsi_host_get_param(struct Scsi_Host *shost,
290 enum iscsi_host_param param, char *buf);
295 extern struct iscsi_cls_session *
296 iscsi_session_setup(struct iscsi_transport *, struct scsi_transport_template *,
297 uint16_t, uint16_t, int, int, uint32_t, uint32_t *);
298 extern void iscsi_session_teardown(struct iscsi_cls_session *);
299 extern struct iscsi_session *class_to_transport_session(struct iscsi_cls_session *);
300 extern void iscsi_session_recovery_timedout(struct iscsi_cls_session *);
301 extern int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
302 enum iscsi_param param, char *buf, int buflen);
303 extern int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
304 enum iscsi_param param, char *buf);
306 #define session_to_cls(_sess) \
307 hostdata_session(_sess->host->hostdata)
310 * connection management
312 extern struct iscsi_cls_conn *iscsi_conn_setup(struct iscsi_cls_session *,
314 extern void iscsi_conn_teardown(struct iscsi_cls_conn *);
315 extern int iscsi_conn_start(struct iscsi_cls_conn *);
316 extern void iscsi_conn_stop(struct iscsi_cls_conn *, int);
317 extern int iscsi_conn_bind(struct iscsi_cls_session *, struct iscsi_cls_conn *,
319 extern void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err);
320 extern int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
321 enum iscsi_param param, char *buf);
324 * pdu and task processing
326 extern void iscsi_update_cmdsn(struct iscsi_session *, struct iscsi_nopin *);
327 extern void iscsi_prep_unsolicit_data_pdu(struct iscsi_cmd_task *,
328 struct iscsi_data *hdr);
329 extern int iscsi_conn_send_pdu(struct iscsi_cls_conn *, struct iscsi_hdr *,
331 extern int iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
333 extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
335 extern int iscsi_verify_itt(struct iscsi_conn *, struct iscsi_hdr *,
337 extern void iscsi_requeue_ctask(struct iscsi_cmd_task *ctask);
342 extern void iscsi_pool_free(struct iscsi_queue *, void **);
343 extern int iscsi_pool_init(struct iscsi_queue *, int, void ***, int);