blob: cf8a1921a392cb3ef2c2dd35d04cb1f174948bca [file] [log] [blame]
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001#ifndef ISCSI_TARGET_CORE_H
2#define ISCSI_TARGET_CORE_H
3
4#include <linux/in.h>
5#include <linux/configfs.h>
6#include <net/sock.h>
7#include <net/tcp.h>
8#include <scsi/scsi_cmnd.h>
9#include <scsi/iscsi_proto.h>
10#include <target/target_core_base.h>
11
Nicholas Bellinger2999ee72013-09-05 15:50:24 -070012#define ISCSIT_VERSION "v4.1.0"
Nicholas Bellingere48354c2011-07-23 06:43:04 +000013#define ISCSI_MAX_DATASN_MISSING_COUNT 16
14#define ISCSI_TX_THREAD_TCP_TIMEOUT 2
15#define ISCSI_RX_THREAD_TCP_TIMEOUT 2
16#define SECONDS_FOR_ASYNC_LOGOUT 10
17#define SECONDS_FOR_ASYNC_TEXT 10
18#define SECONDS_FOR_LOGOUT_COMP 15
19#define WHITE_SPACE " \t\v\f\n\r"
Nicholas Bellinger988e3a82013-08-17 15:49:08 -070020#define ISCSIT_MIN_TAGS 16
21#define ISCSIT_EXTRA_TAGS 8
Nicholas Bellinger837f6452013-09-09 16:24:46 -070022#define ISCSIT_TCP_BACKLOG 256
Nicholas Bellingere48354c2011-07-23 06:43:04 +000023
24/* struct iscsi_node_attrib sanity values */
25#define NA_DATAOUT_TIMEOUT 3
26#define NA_DATAOUT_TIMEOUT_MAX 60
27#define NA_DATAOUT_TIMEOUT_MIX 2
28#define NA_DATAOUT_TIMEOUT_RETRIES 5
29#define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
30#define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
Nicholas Bellingercf0eb282012-10-03 15:42:48 -070031#define NA_NOPIN_TIMEOUT 15
Nicholas Bellingere48354c2011-07-23 06:43:04 +000032#define NA_NOPIN_TIMEOUT_MAX 60
33#define NA_NOPIN_TIMEOUT_MIN 3
Nicholas Bellingercf0eb282012-10-03 15:42:48 -070034#define NA_NOPIN_RESPONSE_TIMEOUT 30
Nicholas Bellingere48354c2011-07-23 06:43:04 +000035#define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
36#define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
37#define NA_RANDOM_DATAIN_PDU_OFFSETS 0
38#define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
39#define NA_RANDOM_R2T_OFFSETS 0
40#define NA_DEFAULT_ERL 0
41#define NA_DEFAULT_ERL_MAX 2
42#define NA_DEFAULT_ERL_MIN 0
43
44/* struct iscsi_tpg_attrib sanity values */
45#define TA_AUTHENTICATION 1
46#define TA_LOGIN_TIMEOUT 15
47#define TA_LOGIN_TIMEOUT_MAX 30
48#define TA_LOGIN_TIMEOUT_MIN 5
49#define TA_NETIF_TIMEOUT 2
50#define TA_NETIF_TIMEOUT_MAX 15
51#define TA_NETIF_TIMEOUT_MIN 2
52#define TA_GENERATE_NODE_ACLS 0
Nicholas Bellinger38f7d6e2013-09-05 15:04:22 -070053#define TA_DEFAULT_CMDSN_DEPTH 64
Nicholas Bellingere48354c2011-07-23 06:43:04 +000054#define TA_DEFAULT_CMDSN_DEPTH_MAX 512
55#define TA_DEFAULT_CMDSN_DEPTH_MIN 1
56#define TA_CACHE_DYNAMIC_ACLS 0
57/* Enabled by default in demo mode (generic_node_acls=1) */
58#define TA_DEMO_MODE_WRITE_PROTECT 1
59/* Disabled by default in production mode w/ explict ACLs */
60#define TA_PROD_MODE_WRITE_PROTECT 0
61#define TA_CACHE_CORE_NPS 0
62
Christoph Hellwigc0427f12011-10-12 11:06:56 -040063
64#define ISCSI_IOV_DATA_BUFFER 5
65
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -080066enum iscsit_transport_type {
Nicholas Bellingere48354c2011-07-23 06:43:04 +000067 ISCSI_TCP = 0,
68 ISCSI_SCTP_TCP = 1,
69 ISCSI_SCTP_UDP = 2,
70 ISCSI_IWARP_TCP = 3,
71 ISCSI_IWARP_SCTP = 4,
72 ISCSI_INFINIBAND = 5,
73};
74
75/* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
76enum target_conn_state_table {
77 TARG_CONN_STATE_FREE = 0x1,
78 TARG_CONN_STATE_XPT_UP = 0x3,
79 TARG_CONN_STATE_IN_LOGIN = 0x4,
80 TARG_CONN_STATE_LOGGED_IN = 0x5,
81 TARG_CONN_STATE_IN_LOGOUT = 0x6,
82 TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
83 TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
84};
85
86/* RFC-3720 7.3.2 Session State Diagram for a Target */
87enum target_sess_state_table {
88 TARG_SESS_STATE_FREE = 0x1,
89 TARG_SESS_STATE_ACTIVE = 0x2,
90 TARG_SESS_STATE_LOGGED_IN = 0x3,
91 TARG_SESS_STATE_FAILED = 0x4,
92 TARG_SESS_STATE_IN_CONTINUE = 0x5,
93};
94
95/* struct iscsi_data_count->type */
96enum data_count_type {
97 ISCSI_RX_DATA = 1,
98 ISCSI_TX_DATA = 2,
99};
100
101/* struct iscsi_datain_req->dr_complete */
102enum datain_req_comp_table {
103 DATAIN_COMPLETE_NORMAL = 1,
104 DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
105 DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
106};
107
108/* struct iscsi_datain_req->recovery */
109enum datain_req_rec_table {
110 DATAIN_WITHIN_COMMAND_RECOVERY = 1,
111 DATAIN_CONNECTION_RECOVERY = 2,
112};
113
114/* struct iscsi_portal_group->state */
115enum tpg_state_table {
116 TPG_STATE_FREE = 0,
117 TPG_STATE_ACTIVE = 1,
118 TPG_STATE_INACTIVE = 2,
119 TPG_STATE_COLD_RESET = 3,
120};
121
122/* struct iscsi_tiqn->tiqn_state */
123enum tiqn_state_table {
124 TIQN_STATE_ACTIVE = 1,
125 TIQN_STATE_SHUTDOWN = 2,
126};
127
128/* struct iscsi_cmd->cmd_flags */
129enum cmd_flags_table {
130 ICF_GOT_LAST_DATAOUT = 0x00000001,
131 ICF_GOT_DATACK_SNACK = 0x00000002,
132 ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
133 ICF_SENT_LAST_R2T = 0x00000008,
134 ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
135 ICF_CONTIG_MEMORY = 0x00000020,
136 ICF_ATTACHED_TO_RQUEUE = 0x00000040,
137 ICF_OOO_CMDSN = 0x00000080,
Nicholas Bellingerba159912013-07-03 03:48:24 -0700138 IFC_SENDTARGETS_ALL = 0x00000100,
139 IFC_SENDTARGETS_SINGLE = 0x00000200,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000140};
141
142/* struct iscsi_cmd->i_state */
143enum cmd_i_state_table {
144 ISTATE_NO_STATE = 0,
145 ISTATE_NEW_CMD = 1,
146 ISTATE_DEFERRED_CMD = 2,
147 ISTATE_UNSOLICITED_DATA = 3,
148 ISTATE_RECEIVE_DATAOUT = 4,
149 ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
150 ISTATE_RECEIVED_LAST_DATAOUT = 6,
151 ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
152 ISTATE_IN_CONNECTION_RECOVERY = 8,
153 ISTATE_RECEIVED_TASKMGT = 9,
154 ISTATE_SEND_ASYNCMSG = 10,
155 ISTATE_SENT_ASYNCMSG = 11,
156 ISTATE_SEND_DATAIN = 12,
157 ISTATE_SEND_LAST_DATAIN = 13,
158 ISTATE_SENT_LAST_DATAIN = 14,
159 ISTATE_SEND_LOGOUTRSP = 15,
160 ISTATE_SENT_LOGOUTRSP = 16,
161 ISTATE_SEND_NOPIN = 17,
162 ISTATE_SENT_NOPIN = 18,
163 ISTATE_SEND_REJECT = 19,
164 ISTATE_SENT_REJECT = 20,
165 ISTATE_SEND_R2T = 21,
166 ISTATE_SENT_R2T = 22,
167 ISTATE_SEND_R2T_RECOVERY = 23,
168 ISTATE_SENT_R2T_RECOVERY = 24,
169 ISTATE_SEND_LAST_R2T = 25,
170 ISTATE_SENT_LAST_R2T = 26,
171 ISTATE_SEND_LAST_R2T_RECOVERY = 27,
172 ISTATE_SENT_LAST_R2T_RECOVERY = 28,
173 ISTATE_SEND_STATUS = 29,
174 ISTATE_SEND_STATUS_BROKEN_PC = 30,
175 ISTATE_SENT_STATUS = 31,
176 ISTATE_SEND_STATUS_RECOVERY = 32,
177 ISTATE_SENT_STATUS_RECOVERY = 33,
178 ISTATE_SEND_TASKMGTRSP = 34,
179 ISTATE_SENT_TASKMGTRSP = 35,
180 ISTATE_SEND_TEXTRSP = 36,
181 ISTATE_SENT_TEXTRSP = 37,
182 ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
183 ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
184 ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
185 ISTATE_REMOVE = 41,
186 ISTATE_FREE = 42,
187};
188
189/* Used for iscsi_recover_cmdsn() return values */
190enum recover_cmdsn_ret_table {
191 CMDSN_ERROR_CANNOT_RECOVER = -1,
192 CMDSN_NORMAL_OPERATION = 0,
193 CMDSN_LOWER_THAN_EXP = 1,
194 CMDSN_HIGHER_THAN_EXP = 2,
195};
196
197/* Used for iscsi_handle_immediate_data() return values */
198enum immedate_data_ret_table {
199 IMMEDIATE_DATA_CANNOT_RECOVER = -1,
200 IMMEDIATE_DATA_NORMAL_OPERATION = 0,
201 IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
202};
203
204/* Used for iscsi_decide_dataout_action() return values */
205enum dataout_action_ret_table {
206 DATAOUT_CANNOT_RECOVER = -1,
207 DATAOUT_NORMAL = 0,
208 DATAOUT_SEND_R2T = 1,
209 DATAOUT_SEND_TO_TRANSPORT = 2,
210 DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
211};
212
213/* Used for struct iscsi_node_auth->naf_flags */
214enum naf_flags_table {
215 NAF_USERID_SET = 0x01,
216 NAF_PASSWORD_SET = 0x02,
217 NAF_USERID_IN_SET = 0x04,
218 NAF_PASSWORD_IN_SET = 0x08,
219};
220
221/* Used by various struct timer_list to manage iSCSI specific state */
222enum iscsi_timer_flags_table {
223 ISCSI_TF_RUNNING = 0x01,
224 ISCSI_TF_STOP = 0x02,
225 ISCSI_TF_EXPIRED = 0x04,
226};
227
228/* Used for struct iscsi_np->np_flags */
229enum np_flags_table {
230 NPF_IP_NETWORK = 0x00,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000231};
232
233/* Used for struct iscsi_np->np_thread_state */
234enum np_thread_state_table {
235 ISCSI_NP_THREAD_ACTIVE = 1,
236 ISCSI_NP_THREAD_INACTIVE = 2,
237 ISCSI_NP_THREAD_RESET = 3,
238 ISCSI_NP_THREAD_SHUTDOWN = 4,
239 ISCSI_NP_THREAD_EXIT = 5,
240};
241
242struct iscsi_conn_ops {
243 u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
244 u8 DataDigest; /* [0,1] == [None,CRC32C] */
245 u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
Nicholas Bellingere004cb22012-09-29 21:47:16 -0700246 u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000247 u8 OFMarker; /* [0,1] == [No,Yes] */
248 u8 IFMarker; /* [0,1] == [No,Yes] */
249 u32 OFMarkInt; /* [1..65535] */
250 u32 IFMarkInt; /* [1..65535] */
Nicholas Bellinger03aa2072013-03-06 21:54:38 -0800251 /*
252 * iSER specific connection parameters
253 */
254 u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
255 u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000256};
257
258struct iscsi_sess_ops {
259 char InitiatorName[224];
260 char InitiatorAlias[256];
261 char TargetName[224];
262 char TargetAlias[256];
263 char TargetAddress[256];
264 u16 TargetPortalGroupTag; /* [0..65535] */
265 u16 MaxConnections; /* [1..65535] */
266 u8 InitialR2T; /* [0,1] == [No,Yes] */
267 u8 ImmediateData; /* [0,1] == [No,Yes] */
268 u32 MaxBurstLength; /* [512..2**24-1] */
269 u32 FirstBurstLength; /* [512..2**24-1] */
270 u16 DefaultTime2Wait; /* [0..3600] */
271 u16 DefaultTime2Retain; /* [0..3600] */
272 u16 MaxOutstandingR2T; /* [1..65535] */
273 u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
274 u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
275 u8 ErrorRecoveryLevel; /* [0..2] */
276 u8 SessionType; /* [0,1] == [Normal,Discovery]*/
Nicholas Bellinger03aa2072013-03-06 21:54:38 -0800277 /*
278 * iSER specific session parameters
279 */
280 u8 RDMAExtensions; /* [0,1] == [No,Yes] */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000281};
282
283struct iscsi_queue_req {
284 int state;
285 struct iscsi_cmd *cmd;
286 struct list_head qr_list;
287};
288
289struct iscsi_data_count {
290 int data_length;
291 int sync_and_steering;
292 enum data_count_type type;
293 u32 iov_count;
294 u32 ss_iov_count;
295 u32 ss_marker_count;
296 struct kvec *iov;
297};
298
299struct iscsi_param_list {
Nicholas Bellinger03aa2072013-03-06 21:54:38 -0800300 bool iser;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000301 struct list_head param_list;
302 struct list_head extra_response_list;
303};
304
305struct iscsi_datain_req {
306 enum datain_req_comp_table dr_complete;
307 int generate_recovery_values;
308 enum datain_req_rec_table recovery;
309 u32 begrun;
310 u32 runlength;
311 u32 data_length;
312 u32 data_offset;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000313 u32 data_sn;
314 u32 next_burst_len;
315 u32 read_data_done;
316 u32 seq_send_order;
Andy Grover8b1e1242012-04-03 15:51:12 -0700317 struct list_head cmd_datain_node;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000318} ____cacheline_aligned;
319
320struct iscsi_ooo_cmdsn {
321 u16 cid;
322 u32 batch_count;
323 u32 cmdsn;
324 u32 exp_cmdsn;
325 struct iscsi_cmd *cmd;
326 struct list_head ooo_list;
327} ____cacheline_aligned;
328
329struct iscsi_datain {
330 u8 flags;
331 u32 data_sn;
332 u32 length;
333 u32 offset;
334} ____cacheline_aligned;
335
336struct iscsi_r2t {
337 int seq_complete;
338 int recovery_r2t;
339 int sent_r2t;
340 u32 r2t_sn;
341 u32 offset;
342 u32 targ_xfer_tag;
343 u32 xfer_len;
344 struct list_head r2t_list;
345} ____cacheline_aligned;
346
347struct iscsi_cmd {
348 enum iscsi_timer_flags_table dataout_timer_flags;
349 /* DataOUT timeout retries */
350 u8 dataout_timeout_retries;
351 /* Within command recovery count */
352 u8 error_recovery_count;
353 /* iSCSI dependent state for out or order CmdSNs */
354 enum cmd_i_state_table deferred_i_state;
355 /* iSCSI dependent state */
356 enum cmd_i_state_table i_state;
357 /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
358 u8 immediate_cmd;
359 /* Immediate data present */
360 u8 immediate_data;
361 /* iSCSI Opcode */
362 u8 iscsi_opcode;
363 /* iSCSI Response Code */
364 u8 iscsi_response;
365 /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
366 u8 logout_reason;
367 /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
368 u8 logout_response;
369 /* MaxCmdSN has been incremented */
370 u8 maxcmdsn_inc;
371 /* Immediate Unsolicited Dataout */
372 u8 unsolicited_data;
Nicholas Bellingerba159912013-07-03 03:48:24 -0700373 /* Reject reason code */
374 u8 reject_reason;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000375 /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
376 u16 logout_cid;
377 /* Command flags */
378 enum cmd_flags_table cmd_flags;
379 /* Initiator Task Tag assigned from Initiator */
Christoph Hellwig66c7db62012-09-26 08:00:39 -0400380 itt_t init_task_tag;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000381 /* Target Transfer Tag assigned from Target */
382 u32 targ_xfer_tag;
383 /* CmdSN assigned from Initiator */
384 u32 cmd_sn;
385 /* ExpStatSN assigned from Initiator */
386 u32 exp_stat_sn;
387 /* StatSN assigned to this ITT */
388 u32 stat_sn;
389 /* DataSN Counter */
390 u32 data_sn;
391 /* R2TSN Counter */
392 u32 r2t_sn;
393 /* Last DataSN acknowledged via DataAck SNACK */
394 u32 acked_data_sn;
395 /* Used for echoing NOPOUT ping data */
396 u32 buf_ptr_size;
397 /* Used to store DataDigest */
398 u32 data_crc;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000399 /* Counter for MaxOutstandingR2T */
400 u32 outstanding_r2ts;
401 /* Next R2T Offset when DataSequenceInOrder=Yes */
402 u32 r2t_offset;
403 /* Iovec current and orig count for iscsi_cmd->iov_data */
404 u32 iov_data_count;
405 u32 orig_iov_data_count;
406 /* Number of miscellaneous iovecs used for IP stack calls */
407 u32 iov_misc_count;
408 /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
409 u32 pdu_count;
410 /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
411 u32 pdu_send_order;
412 /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
413 u32 pdu_start;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000414 /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
415 u32 seq_send_order;
416 /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
417 u32 seq_count;
418 /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
419 u32 seq_no;
420 /* Lowest offset in current DataOUT sequence */
421 u32 seq_start_offset;
422 /* Highest offset in current DataOUT sequence */
423 u32 seq_end_offset;
424 /* Total size in bytes received so far of READ data */
425 u32 read_data_done;
426 /* Total size in bytes received so far of WRITE data */
427 u32 write_data_done;
428 /* Counter for FirstBurstLength key */
429 u32 first_burst_len;
430 /* Counter for MaxBurstLength key */
431 u32 next_burst_len;
432 /* Transfer size used for IP stack calls */
433 u32 tx_size;
434 /* Buffer used for various purposes */
435 void *buf_ptr;
Nicholas Bellinger9864ca92013-06-19 22:43:11 -0700436 /* Used by SendTargets=[iqn.,eui.] discovery */
437 void *text_in_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000438 /* See include/linux/dma-mapping.h */
439 enum dma_data_direction data_direction;
440 /* iSCSI PDU Header + CRC */
441 unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
442 /* Number of times struct iscsi_cmd is present in immediate queue */
443 atomic_t immed_queue_count;
444 atomic_t response_queue_count;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000445 spinlock_t datain_lock;
446 spinlock_t dataout_timeout_lock;
447 /* spinlock for protecting struct iscsi_cmd->i_state */
448 spinlock_t istate_lock;
449 /* spinlock for adding within command recovery entries */
450 spinlock_t error_lock;
451 /* spinlock for adding R2Ts */
452 spinlock_t r2t_lock;
453 /* DataIN List */
454 struct list_head datain_list;
455 /* R2T List */
456 struct list_head cmd_r2t_list;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000457 /* Timer for DataOUT */
458 struct timer_list dataout_timer;
459 /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
460 struct kvec *iov_data;
461 /* Iovecs for miscellaneous purposes */
462#define ISCSI_MISC_IOVECS 5
463 struct kvec iov_misc[ISCSI_MISC_IOVECS];
464 /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
465 struct iscsi_pdu *pdu_list;
466 /* Current struct iscsi_pdu used for DataPDUInOrder=No */
467 struct iscsi_pdu *pdu_ptr;
468 /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
469 struct iscsi_seq *seq_list;
470 /* Current struct iscsi_seq used for DataSequenceInOrder=No */
471 struct iscsi_seq *seq_ptr;
472 /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
473 struct iscsi_tmr_req *tmr_req;
474 /* Connection this command is alligient to */
475 struct iscsi_conn *conn;
476 /* Pointer to connection recovery entry */
477 struct iscsi_conn_recovery *cr;
478 /* Session the command is part of, used for connection recovery */
479 struct iscsi_session *sess;
480 /* list_head for connection list */
Andy Grover2fbb4712012-04-03 15:51:01 -0700481 struct list_head i_conn_node;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000482 /* The TCM I/O descriptor that is accessed via container_of() */
483 struct se_cmd se_cmd;
484 /* Sense buffer that will be mapped into outgoing status */
485#define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
486 unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN];
487
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000488 u32 padding;
489 u8 pad_bytes[4];
490
491 struct scatterlist *first_data_sg;
492 u32 first_data_sg_off;
493 u32 kmapped_nents;
Christoph Hellwigde103c92012-11-06 12:24:09 -0800494 sense_reason_t sense_reason;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000495} ____cacheline_aligned;
496
497struct iscsi_tmr_req {
498 bool task_reassign:1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000499 u32 exp_data_sn;
Christoph Hellwig9f3eb932012-05-20 14:35:02 -0400500 struct iscsi_cmd *ref_cmd;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000501 struct iscsi_conn_recovery *conn_recovery;
502 struct se_tmr_req *se_tmr_req;
503};
504
505struct iscsi_conn {
Roland Dreierd5627ac2012-10-31 09:16:46 -0700506 wait_queue_head_t queues_wq;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000507 /* Authentication Successful for this connection */
508 u8 auth_complete;
509 /* State connection is currently in */
510 u8 conn_state;
511 u8 conn_logout_reason;
512 u8 network_transport;
513 enum iscsi_timer_flags_table nopin_timer_flags;
514 enum iscsi_timer_flags_table nopin_response_timer_flags;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000515 /* Used to know what thread encountered a transport failure */
516 u8 which_thread;
517 /* connection id assigned by the Initiator */
518 u16 cid;
519 /* Remote TCP Port */
520 u16 login_port;
Nicholas Bellinger2f9bc892012-01-16 23:33:48 -0800521 u16 local_port;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000522 int net_size;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800523 int login_family;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000524 u32 auth_id;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000525 u32 conn_flags;
526 /* Used for iscsi_tx_login_rsp() */
Christoph Hellwig66c7db62012-09-26 08:00:39 -0400527 itt_t login_itt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000528 u32 exp_statsn;
529 /* Per connection status sequence number */
530 u32 stat_sn;
531 /* IFMarkInt's Current Value */
532 u32 if_marker;
533 /* OFMarkInt's Current Value */
534 u32 of_marker;
535 /* Used for calculating OFMarker offset to next PDU */
536 u32 of_marker_offset;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000537#define IPV6_ADDRESS_SPACE 48
538 unsigned char login_ip[IPV6_ADDRESS_SPACE];
Nicholas Bellinger2f9bc892012-01-16 23:33:48 -0800539 unsigned char local_ip[IPV6_ADDRESS_SPACE];
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000540 int conn_usage_count;
541 int conn_waiting_on_uc;
542 atomic_t check_immediate_queue;
543 atomic_t conn_logout_remove;
544 atomic_t connection_exit;
545 atomic_t connection_recovery;
546 atomic_t connection_reinstatement;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000547 atomic_t connection_wait_rcfr;
548 atomic_t sleep_on_conn_wait_comp;
549 atomic_t transport_failed;
550 struct completion conn_post_wait_comp;
551 struct completion conn_wait_comp;
552 struct completion conn_wait_rcfr_comp;
553 struct completion conn_waiting_on_uc_comp;
554 struct completion conn_logout_comp;
555 struct completion tx_half_close_comp;
556 struct completion rx_half_close_comp;
557 /* socket used by this connection */
558 struct socket *sock;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700559 void (*orig_data_ready)(struct sock *, int);
Nicholas Bellingerbb048352013-09-05 14:54:04 -0700560 void (*orig_state_change)(struct sock *);
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700561#define LOGIN_FLAGS_READ_ACTIVE 1
562#define LOGIN_FLAGS_CLOSED 2
563#define LOGIN_FLAGS_READY 4
564 unsigned long login_flags;
565 struct delayed_work login_work;
Nicholas Bellingerbb048352013-09-05 14:54:04 -0700566 struct delayed_work login_cleanup_work;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700567 struct iscsi_login *login;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000568 struct timer_list nopin_timer;
569 struct timer_list nopin_response_timer;
570 struct timer_list transport_timer;
Nicholas Bellingerd381a802013-08-15 13:40:17 -0700571 struct task_struct *login_kworker;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000572 /* Spinlock used for add/deleting cmd's from conn_cmd_list */
573 spinlock_t cmd_lock;
574 spinlock_t conn_usage_lock;
575 spinlock_t immed_queue_lock;
576 spinlock_t nopin_timer_lock;
577 spinlock_t response_queue_lock;
578 spinlock_t state_lock;
579 /* libcrypto RX and TX contexts for crc32c */
580 struct hash_desc conn_rx_hash;
581 struct hash_desc conn_tx_hash;
582 /* Used for scheduling TX and RX connection kthreads */
583 cpumask_var_t conn_cpumask;
Dan Carpenterf8d48ae2012-01-15 14:30:24 +0300584 unsigned int conn_rx_reset_cpumask:1;
585 unsigned int conn_tx_reset_cpumask:1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000586 /* list_head of struct iscsi_cmd for this connection */
587 struct list_head conn_cmd_list;
588 struct list_head immed_queue_list;
589 struct list_head response_queue_list;
590 struct iscsi_conn_ops *conn_ops;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800591 struct iscsi_login *conn_login;
592 struct iscsit_transport *conn_transport;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000593 struct iscsi_param_list *param_list;
594 /* Used for per connection auth state machine */
595 void *auth_protocol;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800596 void *context;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000597 struct iscsi_login_thread_s *login_thread;
598 struct iscsi_portal_group *tpg;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700599 struct iscsi_tpg_np *tpg_np;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000600 /* Pointer to parent session */
601 struct iscsi_session *sess;
602 /* Pointer to thread_set in use for this conn's threads */
603 struct iscsi_thread_set *thread_set;
604 /* list_head for session connection list */
605 struct list_head conn_list;
606} ____cacheline_aligned;
607
608struct iscsi_conn_recovery {
609 u16 cid;
610 u32 cmd_count;
611 u32 maxrecvdatasegmentlength;
Nicholas Bellinger1c417f32012-09-29 22:14:51 -0700612 u32 maxxmitdatasegmentlength;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000613 int ready_for_reallegiance;
614 struct list_head conn_recovery_cmd_list;
615 spinlock_t conn_recovery_cmd_lock;
616 struct timer_list time2retain_timer;
617 struct iscsi_session *sess;
618 struct list_head cr_list;
619} ____cacheline_aligned;
620
621struct iscsi_session {
622 u8 initiator_vendor;
623 u8 isid[6];
624 enum iscsi_timer_flags_table time2retain_timer_flags;
625 u8 version_active;
626 u16 cid_called;
627 u16 conn_recovery_count;
628 u16 tsih;
629 /* state session is currently in */
630 u32 session_state;
631 /* session wide counter: initiator assigned task tag */
Christoph Hellwig66c7db62012-09-26 08:00:39 -0400632 itt_t init_task_tag;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000633 /* session wide counter: target assigned task tag */
634 u32 targ_xfer_tag;
635 u32 cmdsn_window;
636
637 /* protects cmdsn values */
638 struct mutex cmdsn_mutex;
639 /* session wide counter: expected command sequence number */
640 u32 exp_cmd_sn;
641 /* session wide counter: maximum allowed command sequence number */
642 u32 max_cmd_sn;
643 struct list_head sess_ooo_cmdsn_list;
644
645 /* LIO specific session ID */
646 u32 sid;
647 char auth_type[8];
648 /* unique within the target */
649 int session_index;
650 /* Used for session reference counting */
651 int session_usage_count;
652 int session_waiting_on_uc;
653 u32 cmd_pdus;
654 u32 rsp_pdus;
655 u64 tx_data_octets;
656 u64 rx_data_octets;
657 u32 conn_digest_errors;
658 u32 conn_timeout_errors;
659 u64 creation_time;
660 spinlock_t session_stats_lock;
661 /* Number of active connections */
662 atomic_t nconn;
663 atomic_t session_continuation;
664 atomic_t session_fall_back_to_erl0;
665 atomic_t session_logout;
666 atomic_t session_reinstatement;
667 atomic_t session_stop_active;
668 atomic_t sleep_on_sess_wait_comp;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000669 /* connection list */
670 struct list_head sess_conn_list;
671 struct list_head cr_active_list;
672 struct list_head cr_inactive_list;
673 spinlock_t conn_lock;
674 spinlock_t cr_a_lock;
675 spinlock_t cr_i_lock;
676 spinlock_t session_usage_lock;
677 spinlock_t ttt_lock;
678 struct completion async_msg_comp;
679 struct completion reinstatement_comp;
680 struct completion session_wait_comp;
681 struct completion session_waiting_on_uc_comp;
682 struct timer_list time2retain_timer;
683 struct iscsi_sess_ops *sess_ops;
684 struct se_session *se_sess;
685 struct iscsi_portal_group *tpg;
686} ____cacheline_aligned;
687
688struct iscsi_login {
689 u8 auth_complete;
690 u8 checked_for_existing;
691 u8 current_stage;
692 u8 leading_connection;
693 u8 first_request;
694 u8 version_min;
695 u8 version_max;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800696 u8 login_complete;
697 u8 login_failed;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700698 bool zero_tsih;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000699 char isid[6];
700 u32 cmd_sn;
Christoph Hellwig66c7db62012-09-26 08:00:39 -0400701 itt_t init_task_tag;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000702 u32 initial_exp_statsn;
703 u32 rsp_length;
704 u16 cid;
705 u16 tsih;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800706 char req[ISCSI_HDR_LEN];
707 char rsp[ISCSI_HDR_LEN];
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000708 char *req_buf;
709 char *rsp_buf;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800710 struct iscsi_conn *conn;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700711 struct iscsi_np *np;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000712} ____cacheline_aligned;
713
714struct iscsi_node_attrib {
715 u32 dataout_timeout;
716 u32 dataout_timeout_retries;
717 u32 default_erl;
718 u32 nopin_timeout;
719 u32 nopin_response_timeout;
720 u32 random_datain_pdu_offsets;
721 u32 random_datain_seq_offsets;
722 u32 random_r2t_offsets;
723 u32 tmr_cold_reset;
724 u32 tmr_warm_reset;
725 struct iscsi_node_acl *nacl;
726};
727
728struct se_dev_entry_s;
729
730struct iscsi_node_auth {
731 enum naf_flags_table naf_flags;
732 int authenticate_target;
733 /* Used for iscsit_global->discovery_auth,
734 * set to zero (auth disabled) by default */
735 int enforce_discovery_auth;
736#define MAX_USER_LEN 256
737#define MAX_PASS_LEN 256
738 char userid[MAX_USER_LEN];
739 char password[MAX_PASS_LEN];
740 char userid_mutual[MAX_USER_LEN];
741 char password_mutual[MAX_PASS_LEN];
742};
743
744#include "iscsi_target_stat.h"
745
746struct iscsi_node_stat_grps {
747 struct config_group iscsi_sess_stats_group;
748 struct config_group iscsi_conn_stats_group;
749};
750
751struct iscsi_node_acl {
752 struct iscsi_node_attrib node_attrib;
753 struct iscsi_node_auth node_auth;
754 struct iscsi_node_stat_grps node_stat_grps;
755 struct se_node_acl se_node_acl;
756};
757
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000758struct iscsi_tpg_attrib {
759 u32 authentication;
760 u32 login_timeout;
761 u32 netif_timeout;
762 u32 generate_node_acls;
763 u32 cache_dynamic_acls;
764 u32 default_cmdsn_depth;
765 u32 demo_mode_write_protect;
766 u32 prod_mode_write_protect;
767 struct iscsi_portal_group *tpg;
768};
769
770struct iscsi_np {
771 int np_network_transport;
772 int np_ip_proto;
773 int np_sock_type;
774 enum np_thread_state_table np_thread_state;
775 enum iscsi_timer_flags_table np_login_timer_flags;
776 u32 np_exports;
777 enum np_flags_table np_flags;
778 unsigned char np_ip[IPV6_ADDRESS_SPACE];
779 u16 np_port;
780 spinlock_t np_thread_lock;
781 struct completion np_restart_comp;
782 struct socket *np_socket;
783 struct __kernel_sockaddr_storage np_sockaddr;
784 struct task_struct *np_thread;
785 struct timer_list np_login_timer;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -0800786 void *np_context;
787 struct iscsit_transport *np_transport;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000788 struct list_head np_list;
789} ____cacheline_aligned;
790
791struct iscsi_tpg_np {
792 struct iscsi_np *tpg_np;
793 struct iscsi_portal_group *tpg;
794 struct iscsi_tpg_np *tpg_np_parent;
795 struct list_head tpg_np_list;
796 struct list_head tpg_np_child_list;
797 struct list_head tpg_np_parent_list;
798 struct se_tpg_np se_tpg_np;
799 spinlock_t tpg_np_parent_lock;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700800 struct completion tpg_np_comp;
801 struct kref tpg_np_kref;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000802};
803
804struct iscsi_portal_group {
805 unsigned char tpg_chap_id;
806 /* TPG State */
807 enum tpg_state_table tpg_state;
808 /* Target Portal Group Tag */
809 u16 tpgt;
810 /* Id assigned to target sessions */
811 u16 ntsih;
812 /* Number of active sessions */
813 u32 nsessions;
814 /* Number of Network Portals available for this TPG */
815 u32 num_tpg_nps;
816 /* Per TPG LIO specific session ID. */
817 u32 sid;
818 /* Spinlock for adding/removing Network Portals */
819 spinlock_t tpg_np_lock;
820 spinlock_t tpg_state_lock;
821 struct se_portal_group tpg_se_tpg;
822 struct mutex tpg_access_lock;
Nicholas Bellingera91eb7d2013-08-15 12:49:02 -0700823 struct semaphore np_login_sem;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000824 struct iscsi_tpg_attrib tpg_attrib;
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700825 struct iscsi_node_auth tpg_demo_auth;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000826 /* Pointer to default list of iSCSI parameters for TPG */
827 struct iscsi_param_list *param_list;
828 struct iscsi_tiqn *tpg_tiqn;
829 struct list_head tpg_gnp_list;
830 struct list_head tpg_list;
831} ____cacheline_aligned;
832
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000833struct iscsi_wwn_stat_grps {
834 struct config_group iscsi_stat_group;
835 struct config_group iscsi_instance_group;
836 struct config_group iscsi_sess_err_group;
837 struct config_group iscsi_tgt_attr_group;
838 struct config_group iscsi_login_stats_group;
839 struct config_group iscsi_logout_stats_group;
840};
841
842struct iscsi_tiqn {
843#define ISCSI_IQN_LEN 224
844 unsigned char tiqn[ISCSI_IQN_LEN];
845 enum tiqn_state_table tiqn_state;
846 int tiqn_access_count;
847 u32 tiqn_active_tpgs;
848 u32 tiqn_ntpgs;
849 u32 tiqn_num_tpg_nps;
850 u32 tiqn_nsessions;
851 struct list_head tiqn_list;
852 struct list_head tiqn_tpg_list;
853 spinlock_t tiqn_state_lock;
854 spinlock_t tiqn_tpg_lock;
855 struct se_wwn tiqn_wwn;
856 struct iscsi_wwn_stat_grps tiqn_stat_grps;
857 int tiqn_index;
858 struct iscsi_sess_err_stats sess_err_stats;
859 struct iscsi_login_stats login_stats;
860 struct iscsi_logout_stats logout_stats;
861} ____cacheline_aligned;
862
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000863struct iscsit_global {
864 /* In core shutdown */
865 u32 in_shutdown;
866 u32 active_ts;
867 /* Unique identifier used for the authentication daemon */
868 u32 auth_id;
869 u32 inactive_ts;
870 /* Thread Set bitmap count */
871 int ts_bitmap_count;
872 /* Thread Set bitmap pointer */
873 unsigned long *ts_bitmap;
874 /* Used for iSCSI discovery session authentication */
875 struct iscsi_node_acl discovery_acl;
876 struct iscsi_portal_group *discovery_tpg;
877};
878
879#endif /* ISCSI_TARGET_CORE_H */