diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2006-04-06 22:26:46 -0400 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-04-14 16:19:42 -0400 |
commit | 5bb0b55a3283369f1cd8ac76a6d8bda8e7a77055 (patch) | |
tree | efecf16a9627f624df15822c90c5980e0a0ef289 /drivers/scsi/iscsi_tcp.h | |
parent | 7996a778ff8c717cb1a7a294475c59cc8f1e9fb8 (diff) |
[SCSI] iscsi: convert iscsi tcp to libiscsi
This just converts iscsi_tcp to the lib
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/iscsi_tcp.h')
-rw-r--r-- | drivers/scsi/iscsi_tcp.h | 182 |
1 files changed, 16 insertions, 166 deletions
diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h index 12ef64179b4c..c5918854d595 100644 --- a/drivers/scsi/iscsi_tcp.h +++ b/drivers/scsi/iscsi_tcp.h | |||
@@ -2,7 +2,8 @@ | |||
2 | * iSCSI Initiator TCP Transport | 2 | * iSCSI Initiator TCP Transport |
3 | * Copyright (C) 2004 Dmitry Yusupov | 3 | * Copyright (C) 2004 Dmitry Yusupov |
4 | * Copyright (C) 2004 Alex Aizman | 4 | * Copyright (C) 2004 Alex Aizman |
5 | * Copyright (C) 2005 Mike Christie | 5 | * Copyright (C) 2005 - 2006 Mike Christie |
6 | * Copyright (C) 2006 Red Hat, Inc. All rights reserved. | ||
6 | * maintained by open-iscsi@googlegroups.com | 7 | * maintained by open-iscsi@googlegroups.com |
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -21,20 +22,7 @@ | |||
21 | #ifndef ISCSI_TCP_H | 22 | #ifndef ISCSI_TCP_H |
22 | #define ISCSI_TCP_H | 23 | #define ISCSI_TCP_H |
23 | 24 | ||
24 | /* Session's states */ | 25 | #include <scsi/libiscsi.h> |
25 | #define ISCSI_STATE_FREE 1 | ||
26 | #define ISCSI_STATE_LOGGED_IN 2 | ||
27 | #define ISCSI_STATE_FAILED 3 | ||
28 | #define ISCSI_STATE_TERMINATE 4 | ||
29 | |||
30 | /* Connection's states */ | ||
31 | #define ISCSI_CONN_INITIAL_STAGE 0 | ||
32 | #define ISCSI_CONN_STARTED 1 | ||
33 | #define ISCSI_CONN_STOPPED 2 | ||
34 | #define ISCSI_CONN_CLEANUP_WAIT 3 | ||
35 | |||
36 | /* Connection suspend "bit" */ | ||
37 | #define SUSPEND_BIT 1 | ||
38 | 26 | ||
39 | /* Socket's Receive state machine */ | 27 | /* Socket's Receive state machine */ |
40 | #define IN_PROGRESS_WAIT_HEADER 0x0 | 28 | #define IN_PROGRESS_WAIT_HEADER 0x0 |
@@ -42,12 +30,6 @@ | |||
42 | #define IN_PROGRESS_DATA_RECV 0x2 | 30 | #define IN_PROGRESS_DATA_RECV 0x2 |
43 | #define IN_PROGRESS_DDIGEST_RECV 0x3 | 31 | #define IN_PROGRESS_DDIGEST_RECV 0x3 |
44 | 32 | ||
45 | /* Task Mgmt states */ | ||
46 | #define TMABORT_INITIAL 0x0 | ||
47 | #define TMABORT_SUCCESS 0x1 | ||
48 | #define TMABORT_FAILED 0x2 | ||
49 | #define TMABORT_TIMEDOUT 0x3 | ||
50 | |||
51 | /* xmit state machine */ | 33 | /* xmit state machine */ |
52 | #define XMSTATE_IDLE 0x0 | 34 | #define XMSTATE_IDLE 0x0 |
53 | #define XMSTATE_R_HDR 0x1 | 35 | #define XMSTATE_R_HDR 0x1 |
@@ -62,34 +44,14 @@ | |||
62 | #define XMSTATE_W_PAD 0x200 | 44 | #define XMSTATE_W_PAD 0x200 |
63 | #define XMSTATE_DATA_DIGEST 0x400 | 45 | #define XMSTATE_DATA_DIGEST 0x400 |
64 | 46 | ||
65 | #define ISCSI_CONN_MAX 1 | ||
66 | #define ISCSI_CONN_RCVBUF_MIN 262144 | 47 | #define ISCSI_CONN_RCVBUF_MIN 262144 |
67 | #define ISCSI_CONN_SNDBUF_MIN 262144 | 48 | #define ISCSI_CONN_SNDBUF_MIN 262144 |
68 | #define ISCSI_PAD_LEN 4 | 49 | #define ISCSI_PAD_LEN 4 |
69 | #define ISCSI_R2T_MAX 16 | 50 | #define ISCSI_R2T_MAX 16 |
70 | #define ISCSI_XMIT_CMDS_MAX 128 /* must be power of 2 */ | ||
71 | #define ISCSI_MGMT_CMDS_MAX 32 /* must be power of 2 */ | ||
72 | #define ISCSI_MGMT_ITT_OFFSET 0xa00 | ||
73 | #define ISCSI_SG_TABLESIZE SG_ALL | 51 | #define ISCSI_SG_TABLESIZE SG_ALL |
74 | #define ISCSI_DEF_CMD_PER_LUN 32 | ||
75 | #define ISCSI_MAX_CMD_PER_LUN 128 | ||
76 | #define ISCSI_TCP_MAX_CMD_LEN 16 | 52 | #define ISCSI_TCP_MAX_CMD_LEN 16 |
77 | 53 | ||
78 | #define ITT_MASK (0xfff) | 54 | struct socket; |
79 | #define CID_SHIFT 12 | ||
80 | #define CID_MASK (0xffff<<CID_SHIFT) | ||
81 | #define AGE_SHIFT 28 | ||
82 | #define AGE_MASK (0xf<<AGE_SHIFT) | ||
83 | |||
84 | struct iscsi_queue { | ||
85 | struct kfifo *queue; /* FIFO Queue */ | ||
86 | void **pool; /* Pool of elements */ | ||
87 | int max; /* Max number of elements */ | ||
88 | }; | ||
89 | |||
90 | struct iscsi_session; | ||
91 | struct iscsi_cmd_task; | ||
92 | struct iscsi_mgmt_task; | ||
93 | 55 | ||
94 | /* Socket connection recieve helper */ | 56 | /* Socket connection recieve helper */ |
95 | struct iscsi_tcp_recv { | 57 | struct iscsi_tcp_recv { |
@@ -104,48 +66,32 @@ struct iscsi_tcp_recv { | |||
104 | struct iscsi_cmd_task *ctask; /* current cmd in progress */ | 66 | struct iscsi_cmd_task *ctask; /* current cmd in progress */ |
105 | 67 | ||
106 | /* copied and flipped values */ | 68 | /* copied and flipped values */ |
107 | int opcode; | ||
108 | int flags; | ||
109 | int cmd_status; | ||
110 | int ahslen; | ||
111 | int datalen; | 69 | int datalen; |
112 | uint32_t itt; | ||
113 | int datadgst; | 70 | int datadgst; |
71 | char zero_copy_hdr; | ||
114 | }; | 72 | }; |
115 | 73 | ||
116 | struct iscsi_cls_conn; | 74 | struct iscsi_tcp_conn { |
117 | 75 | struct iscsi_conn *iscsi_conn; | |
118 | struct iscsi_conn { | 76 | struct socket *sock; |
119 | struct iscsi_cls_conn *cls_conn; /* ptr to class connection */ | ||
120 | struct iscsi_hdr hdr; /* header placeholder */ | 77 | struct iscsi_hdr hdr; /* header placeholder */ |
121 | char hdrext[4*sizeof(__u16) + | 78 | char hdrext[4*sizeof(__u16) + |
122 | sizeof(__u32)]; | 79 | sizeof(__u32)]; |
123 | int data_copied; | 80 | int data_copied; |
124 | char *data; /* data placeholder */ | 81 | char *data; /* data placeholder */ |
125 | struct socket *sock; /* TCP socket */ | ||
126 | int data_size; /* actual recv_dlength */ | 82 | int data_size; /* actual recv_dlength */ |
127 | int stop_stage; /* conn_stop() flag: * | 83 | int stop_stage; /* conn_stop() flag: * |
128 | * stop to recover, * | 84 | * stop to recover, * |
129 | * stop to terminate */ | 85 | * stop to terminate */ |
130 | /* iSCSI connection-wide sequencing */ | 86 | /* iSCSI connection-wide sequencing */ |
131 | uint32_t exp_statsn; | ||
132 | int hdr_size; /* PDU header size */ | 87 | int hdr_size; /* PDU header size */ |
133 | unsigned long suspend_rx; /* suspend Rx */ | ||
134 | 88 | ||
135 | struct crypto_tfm *rx_tfm; /* CRC32C (Rx) */ | 89 | struct crypto_tfm *rx_tfm; /* CRC32C (Rx) */ |
136 | struct crypto_tfm *data_rx_tfm; /* CRC32C (Rx) for data */ | 90 | struct crypto_tfm *data_rx_tfm; /* CRC32C (Rx) for data */ |
137 | 91 | ||
138 | /* control data */ | 92 | /* control data */ |
139 | int senselen; /* scsi sense length */ | ||
140 | int id; /* CID */ | ||
141 | struct iscsi_tcp_recv in; /* TCP receive context */ | 93 | struct iscsi_tcp_recv in; /* TCP receive context */ |
142 | struct iscsi_session *session; /* parent session */ | ||
143 | struct list_head item; /* maintains list of conns */ | ||
144 | int in_progress; /* connection state machine */ | 94 | int in_progress; /* connection state machine */ |
145 | int c_stage; /* connection state */ | ||
146 | struct iscsi_mgmt_task *login_mtask; /* mtask used for login/text */ | ||
147 | struct iscsi_mgmt_task *mtask; /* xmit mtask in progress */ | ||
148 | struct iscsi_cmd_task *ctask; /* xmit ctask in progress */ | ||
149 | 95 | ||
150 | /* old values for socket callbacks */ | 96 | /* old values for socket callbacks */ |
151 | void (*old_data_ready)(struct sock *, int); | 97 | void (*old_data_ready)(struct sock *, int); |
@@ -155,95 +101,14 @@ struct iscsi_conn { | |||
155 | /* xmit */ | 101 | /* xmit */ |
156 | struct crypto_tfm *tx_tfm; /* CRC32C (Tx) */ | 102 | struct crypto_tfm *tx_tfm; /* CRC32C (Tx) */ |
157 | struct crypto_tfm *data_tx_tfm; /* CRC32C (Tx) for data */ | 103 | struct crypto_tfm *data_tx_tfm; /* CRC32C (Tx) for data */ |
158 | struct kfifo *writequeue; /* write cmds for Data-Outs */ | ||
159 | struct kfifo *immqueue; /* immediate xmit queue */ | ||
160 | struct kfifo *mgmtqueue; /* mgmt (control) xmit queue */ | ||
161 | struct kfifo *xmitqueue; /* data-path cmd queue */ | ||
162 | struct list_head run_list; /* list of cmds in progress */ | ||
163 | struct work_struct xmitwork; /* per-conn. xmit workqueue */ | ||
164 | struct mutex xmitmutex; /* serializes connection xmit, | ||
165 | * access to kfifos: * | ||
166 | * xmitqueue, writequeue, * | ||
167 | * immqueue, mgmtqueue */ | ||
168 | unsigned long suspend_tx; /* suspend Tx */ | ||
169 | |||
170 | /* abort */ | ||
171 | wait_queue_head_t ehwait; /* used in eh_abort() */ | ||
172 | struct iscsi_tm tmhdr; | ||
173 | struct timer_list tmabort_timer; /* abort timer */ | ||
174 | int tmabort_state; /* see TMABORT_INITIAL, etc.*/ | ||
175 | |||
176 | /* negotiated params */ | ||
177 | int max_recv_dlength; | ||
178 | int max_xmit_dlength; | ||
179 | int hdrdgst_en; | ||
180 | int datadgst_en; | ||
181 | 104 | ||
182 | /* MIB-statistics */ | 105 | /* MIB custom statistics */ |
183 | uint64_t txdata_octets; | ||
184 | uint64_t rxdata_octets; | ||
185 | uint32_t scsicmd_pdus_cnt; | ||
186 | uint32_t dataout_pdus_cnt; | ||
187 | uint32_t scsirsp_pdus_cnt; | ||
188 | uint32_t datain_pdus_cnt; | ||
189 | uint32_t r2t_pdus_cnt; | ||
190 | uint32_t tmfcmd_pdus_cnt; | ||
191 | int32_t tmfrsp_pdus_cnt; | ||
192 | |||
193 | /* custom statistics */ | ||
194 | uint32_t sendpage_failures_cnt; | 106 | uint32_t sendpage_failures_cnt; |
195 | uint32_t discontiguous_hdr_cnt; | 107 | uint32_t discontiguous_hdr_cnt; |
196 | uint32_t eh_abort_cnt; | ||
197 | 108 | ||
198 | ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); | 109 | ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); |
199 | }; | 110 | }; |
200 | 111 | ||
201 | struct iscsi_session { | ||
202 | /* iSCSI session-wide sequencing */ | ||
203 | uint32_t cmdsn; | ||
204 | uint32_t exp_cmdsn; | ||
205 | uint32_t max_cmdsn; | ||
206 | |||
207 | /* configuration */ | ||
208 | int initial_r2t_en; | ||
209 | int max_r2t; | ||
210 | int imm_data_en; | ||
211 | int first_burst; | ||
212 | int max_burst; | ||
213 | int time2wait; | ||
214 | int time2retain; | ||
215 | int pdu_inorder_en; | ||
216 | int dataseq_inorder_en; | ||
217 | int erl; | ||
218 | int ifmarker_en; | ||
219 | int ofmarker_en; | ||
220 | |||
221 | /* control data */ | ||
222 | struct Scsi_Host *host; | ||
223 | int id; | ||
224 | struct iscsi_conn *leadconn; /* leading connection */ | ||
225 | spinlock_t lock; /* protects session state, * | ||
226 | * sequence numbers, * | ||
227 | * session resources: * | ||
228 | * - cmdpool, * | ||
229 | * - mgmtpool, * | ||
230 | * - r2tpool */ | ||
231 | int state; /* session state */ | ||
232 | int recovery_failed; | ||
233 | struct list_head item; | ||
234 | void *auth_client; | ||
235 | int conn_cnt; | ||
236 | int age; /* counts session re-opens */ | ||
237 | |||
238 | struct list_head connections; /* list of connections */ | ||
239 | int cmds_max; /* size of cmds array */ | ||
240 | struct iscsi_cmd_task **cmds; /* Original Cmds arr */ | ||
241 | struct iscsi_queue cmdpool; /* PDU's pool */ | ||
242 | int mgmtpool_max; /* size of mgmt array */ | ||
243 | struct iscsi_mgmt_task **mgmt_cmds; /* Original mgmt arr */ | ||
244 | struct iscsi_queue mgmtpool; /* Mgmt PDU's pool */ | ||
245 | }; | ||
246 | |||
247 | struct iscsi_buf { | 112 | struct iscsi_buf { |
248 | struct scatterlist sg; | 113 | struct scatterlist sg; |
249 | unsigned int sent; | 114 | unsigned int sent; |
@@ -259,16 +124,13 @@ struct iscsi_data_task { | |||
259 | }; | 124 | }; |
260 | #define ISCSI_DTASK_DEFAULT_MAX ISCSI_SG_TABLESIZE * PAGE_SIZE / 512 | 125 | #define ISCSI_DTASK_DEFAULT_MAX ISCSI_SG_TABLESIZE * PAGE_SIZE / 512 |
261 | 126 | ||
262 | struct iscsi_mgmt_task { | 127 | struct iscsi_tcp_mgmt_task { |
263 | struct iscsi_hdr hdr; /* mgmt. PDU */ | 128 | struct iscsi_hdr hdr; |
264 | char hdrext[sizeof(__u32)]; /* Header-Digest */ | 129 | char hdrext[sizeof(__u32)]; /* Header-Digest */ |
265 | char *data; /* mgmt payload */ | ||
266 | int xmstate; /* mgmt xmit progress */ | 130 | int xmstate; /* mgmt xmit progress */ |
267 | int data_count; /* counts data to be sent */ | ||
268 | struct iscsi_buf headbuf; /* header buffer */ | 131 | struct iscsi_buf headbuf; /* header buffer */ |
269 | struct iscsi_buf sendbuf; /* in progress buffer */ | 132 | struct iscsi_buf sendbuf; /* in progress buffer */ |
270 | int sent; | 133 | int sent; |
271 | uint32_t itt; /* this ITT */ | ||
272 | }; | 134 | }; |
273 | 135 | ||
274 | struct iscsi_r2t_info { | 136 | struct iscsi_r2t_info { |
@@ -285,34 +147,22 @@ struct iscsi_r2t_info { | |||
285 | struct iscsi_data_task *dtask; /* which data task */ | 147 | struct iscsi_data_task *dtask; /* which data task */ |
286 | }; | 148 | }; |
287 | 149 | ||
288 | struct iscsi_cmd_task { | 150 | struct iscsi_tcp_cmd_task { |
289 | struct iscsi_cmd hdr; /* iSCSI PDU header */ | 151 | struct iscsi_cmd hdr; |
290 | char hdrext[4*sizeof(__u16)+ /* AHS */ | 152 | char hdrext[4*sizeof(__u16)+ /* AHS */ |
291 | sizeof(__u32)]; /* HeaderDigest */ | 153 | sizeof(__u32)]; /* HeaderDigest */ |
292 | char pad[ISCSI_PAD_LEN]; | 154 | char pad[ISCSI_PAD_LEN]; |
293 | int itt; /* this ITT */ | 155 | int pad_count; /* padded bytes */ |
294 | int datasn; /* DataSN */ | ||
295 | struct iscsi_buf headbuf; /* header buf (xmit) */ | 156 | struct iscsi_buf headbuf; /* header buf (xmit) */ |
296 | struct iscsi_buf sendbuf; /* in progress buffer*/ | 157 | struct iscsi_buf sendbuf; /* in progress buffer*/ |
158 | int xmstate; /* xmit xtate machine */ | ||
297 | int sent; | 159 | int sent; |
298 | struct scatterlist *sg; /* per-cmd SG list */ | 160 | struct scatterlist *sg; /* per-cmd SG list */ |
299 | struct scatterlist *bad_sg; /* assert statement */ | 161 | struct scatterlist *bad_sg; /* assert statement */ |
300 | int sg_count; /* SG's to process */ | 162 | int sg_count; /* SG's to process */ |
301 | uint32_t unsol_datasn; | ||
302 | uint32_t exp_r2tsn; | 163 | uint32_t exp_r2tsn; |
303 | int xmstate; /* xmit xtate machine */ | ||
304 | int imm_count; /* imm-data (bytes) */ | ||
305 | int unsol_count; /* unsolicited (bytes)*/ | ||
306 | int r2t_data_count; /* R2T Data-Out bytes */ | 164 | int r2t_data_count; /* R2T Data-Out bytes */ |
307 | int data_count; /* remaining Data-Out */ | ||
308 | int pad_count; /* padded bytes */ | ||
309 | struct scsi_cmnd *sc; /* associated SCSI cmd*/ | ||
310 | int total_length; | ||
311 | int data_offset; | 165 | int data_offset; |
312 | struct iscsi_conn *conn; /* used connection */ | ||
313 | struct iscsi_mgmt_task *mtask; /* tmf mtask in progr */ | ||
314 | |||
315 | struct list_head running; /* running cmd list */ | ||
316 | struct iscsi_r2t_info *r2t; /* in progress R2T */ | 166 | struct iscsi_r2t_info *r2t; /* in progress R2T */ |
317 | struct iscsi_queue r2tpool; | 167 | struct iscsi_queue r2tpool; |
318 | struct kfifo *r2tqueue; | 168 | struct kfifo *r2tqueue; |