Linux 4.13.16
[linux/fpc-iii.git] / include / target / iscsi / iscsi_target_core.h
blobfb87d32f5e513de3c2a1b7c6f402b5f48e401c45
1 #ifndef ISCSI_TARGET_CORE_H
2 #define ISCSI_TARGET_CORE_H
4 #include <linux/dma-direction.h> /* enum dma_data_direction */
5 #include <linux/list.h> /* struct list_head */
6 #include <linux/socket.h> /* struct sockaddr_storage */
7 #include <linux/types.h> /* u8 */
8 #include <scsi/iscsi_proto.h> /* itt_t */
9 #include <target/target_core_base.h> /* struct se_cmd */
11 struct sock;
13 #define ISCSIT_VERSION "v4.1.0"
14 #define ISCSI_MAX_DATASN_MISSING_COUNT 16
15 #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
16 #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
17 #define SECONDS_FOR_ASYNC_LOGOUT 10
18 #define SECONDS_FOR_ASYNC_TEXT 10
19 #define SECONDS_FOR_LOGOUT_COMP 15
20 #define WHITE_SPACE " \t\v\f\n\r"
21 #define ISCSIT_MIN_TAGS 16
22 #define ISCSIT_EXTRA_TAGS 8
23 #define ISCSIT_TCP_BACKLOG 256
24 #define ISCSI_RX_THREAD_NAME "iscsi_trx"
25 #define ISCSI_TX_THREAD_NAME "iscsi_ttx"
27 /* struct iscsi_node_attrib sanity values */
28 #define NA_DATAOUT_TIMEOUT 3
29 #define NA_DATAOUT_TIMEOUT_MAX 60
30 #define NA_DATAOUT_TIMEOUT_MIX 2
31 #define NA_DATAOUT_TIMEOUT_RETRIES 5
32 #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
33 #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
34 #define NA_NOPIN_TIMEOUT 15
35 #define NA_NOPIN_TIMEOUT_MAX 60
36 #define NA_NOPIN_TIMEOUT_MIN 3
37 #define NA_NOPIN_RESPONSE_TIMEOUT 30
38 #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
39 #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
40 #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
41 #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
42 #define NA_RANDOM_R2T_OFFSETS 0
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
53 #define TA_DEFAULT_CMDSN_DEPTH 64
54 #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_DEMO_MODE_DISCOVERY 1
62 #define TA_DEFAULT_ERL 0
63 #define TA_CACHE_CORE_NPS 0
64 /* T10 protection information disabled by default */
65 #define TA_DEFAULT_T10_PI 0
66 #define TA_DEFAULT_FABRIC_PROT_TYPE 0
67 /* TPG status needs to be enabled to return sendtargets discovery endpoint info */
68 #define TA_DEFAULT_TPG_ENABLED_SENDTARGETS 1
70 * Used to control the sending of keys with optional to respond state bit,
71 * as a workaround for non RFC compliant initiators,that do not propose,
72 * nor respond to specific keys required for login to complete.
74 * See iscsi_check_proposer_for_optional_reply() for more details.
76 #define TA_DEFAULT_LOGIN_KEYS_WORKAROUND 1
78 #define ISCSI_IOV_DATA_BUFFER 5
80 enum iscsit_transport_type {
81 ISCSI_TCP = 0,
82 ISCSI_SCTP_TCP = 1,
83 ISCSI_SCTP_UDP = 2,
84 ISCSI_IWARP_TCP = 3,
85 ISCSI_IWARP_SCTP = 4,
86 ISCSI_INFINIBAND = 5,
87 ISCSI_CXGBIT = 6,
90 /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
91 enum target_conn_state_table {
92 TARG_CONN_STATE_FREE = 0x1,
93 TARG_CONN_STATE_XPT_UP = 0x3,
94 TARG_CONN_STATE_IN_LOGIN = 0x4,
95 TARG_CONN_STATE_LOGGED_IN = 0x5,
96 TARG_CONN_STATE_IN_LOGOUT = 0x6,
97 TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
98 TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
101 /* RFC-3720 7.3.2 Session State Diagram for a Target */
102 enum target_sess_state_table {
103 TARG_SESS_STATE_FREE = 0x1,
104 TARG_SESS_STATE_ACTIVE = 0x2,
105 TARG_SESS_STATE_LOGGED_IN = 0x3,
106 TARG_SESS_STATE_FAILED = 0x4,
107 TARG_SESS_STATE_IN_CONTINUE = 0x5,
110 /* struct iscsi_data_count->type */
111 enum data_count_type {
112 ISCSI_RX_DATA = 1,
113 ISCSI_TX_DATA = 2,
116 /* struct iscsi_datain_req->dr_complete */
117 enum datain_req_comp_table {
118 DATAIN_COMPLETE_NORMAL = 1,
119 DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
120 DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
123 /* struct iscsi_datain_req->recovery */
124 enum datain_req_rec_table {
125 DATAIN_WITHIN_COMMAND_RECOVERY = 1,
126 DATAIN_CONNECTION_RECOVERY = 2,
129 /* struct iscsi_portal_group->state */
130 enum tpg_state_table {
131 TPG_STATE_FREE = 0,
132 TPG_STATE_ACTIVE = 1,
133 TPG_STATE_INACTIVE = 2,
134 TPG_STATE_COLD_RESET = 3,
137 /* struct iscsi_tiqn->tiqn_state */
138 enum tiqn_state_table {
139 TIQN_STATE_ACTIVE = 1,
140 TIQN_STATE_SHUTDOWN = 2,
143 /* struct iscsi_cmd->cmd_flags */
144 enum cmd_flags_table {
145 ICF_GOT_LAST_DATAOUT = 0x00000001,
146 ICF_GOT_DATACK_SNACK = 0x00000002,
147 ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
148 ICF_SENT_LAST_R2T = 0x00000008,
149 ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
150 ICF_CONTIG_MEMORY = 0x00000020,
151 ICF_ATTACHED_TO_RQUEUE = 0x00000040,
152 ICF_OOO_CMDSN = 0x00000080,
153 ICF_SENDTARGETS_ALL = 0x00000100,
154 ICF_SENDTARGETS_SINGLE = 0x00000200,
157 /* struct iscsi_cmd->i_state */
158 enum cmd_i_state_table {
159 ISTATE_NO_STATE = 0,
160 ISTATE_NEW_CMD = 1,
161 ISTATE_DEFERRED_CMD = 2,
162 ISTATE_UNSOLICITED_DATA = 3,
163 ISTATE_RECEIVE_DATAOUT = 4,
164 ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
165 ISTATE_RECEIVED_LAST_DATAOUT = 6,
166 ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
167 ISTATE_IN_CONNECTION_RECOVERY = 8,
168 ISTATE_RECEIVED_TASKMGT = 9,
169 ISTATE_SEND_ASYNCMSG = 10,
170 ISTATE_SENT_ASYNCMSG = 11,
171 ISTATE_SEND_DATAIN = 12,
172 ISTATE_SEND_LAST_DATAIN = 13,
173 ISTATE_SENT_LAST_DATAIN = 14,
174 ISTATE_SEND_LOGOUTRSP = 15,
175 ISTATE_SENT_LOGOUTRSP = 16,
176 ISTATE_SEND_NOPIN = 17,
177 ISTATE_SENT_NOPIN = 18,
178 ISTATE_SEND_REJECT = 19,
179 ISTATE_SENT_REJECT = 20,
180 ISTATE_SEND_R2T = 21,
181 ISTATE_SENT_R2T = 22,
182 ISTATE_SEND_R2T_RECOVERY = 23,
183 ISTATE_SENT_R2T_RECOVERY = 24,
184 ISTATE_SEND_LAST_R2T = 25,
185 ISTATE_SENT_LAST_R2T = 26,
186 ISTATE_SEND_LAST_R2T_RECOVERY = 27,
187 ISTATE_SENT_LAST_R2T_RECOVERY = 28,
188 ISTATE_SEND_STATUS = 29,
189 ISTATE_SEND_STATUS_BROKEN_PC = 30,
190 ISTATE_SENT_STATUS = 31,
191 ISTATE_SEND_STATUS_RECOVERY = 32,
192 ISTATE_SENT_STATUS_RECOVERY = 33,
193 ISTATE_SEND_TASKMGTRSP = 34,
194 ISTATE_SENT_TASKMGTRSP = 35,
195 ISTATE_SEND_TEXTRSP = 36,
196 ISTATE_SENT_TEXTRSP = 37,
197 ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
198 ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
199 ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
200 ISTATE_REMOVE = 41,
201 ISTATE_FREE = 42,
204 /* Used for iscsi_recover_cmdsn() return values */
205 enum recover_cmdsn_ret_table {
206 CMDSN_ERROR_CANNOT_RECOVER = -1,
207 CMDSN_NORMAL_OPERATION = 0,
208 CMDSN_LOWER_THAN_EXP = 1,
209 CMDSN_HIGHER_THAN_EXP = 2,
210 CMDSN_MAXCMDSN_OVERRUN = 3,
213 /* Used for iscsi_handle_immediate_data() return values */
214 enum immedate_data_ret_table {
215 IMMEDIATE_DATA_CANNOT_RECOVER = -1,
216 IMMEDIATE_DATA_NORMAL_OPERATION = 0,
217 IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
220 /* Used for iscsi_decide_dataout_action() return values */
221 enum dataout_action_ret_table {
222 DATAOUT_CANNOT_RECOVER = -1,
223 DATAOUT_NORMAL = 0,
224 DATAOUT_SEND_R2T = 1,
225 DATAOUT_SEND_TO_TRANSPORT = 2,
226 DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
229 /* Used for struct iscsi_node_auth->naf_flags */
230 enum naf_flags_table {
231 NAF_USERID_SET = 0x01,
232 NAF_PASSWORD_SET = 0x02,
233 NAF_USERID_IN_SET = 0x04,
234 NAF_PASSWORD_IN_SET = 0x08,
237 /* Used by various struct timer_list to manage iSCSI specific state */
238 enum iscsi_timer_flags_table {
239 ISCSI_TF_RUNNING = 0x01,
240 ISCSI_TF_STOP = 0x02,
241 ISCSI_TF_EXPIRED = 0x04,
244 /* Used for struct iscsi_np->np_flags */
245 enum np_flags_table {
246 NPF_IP_NETWORK = 0x00,
249 /* Used for struct iscsi_np->np_thread_state */
250 enum np_thread_state_table {
251 ISCSI_NP_THREAD_ACTIVE = 1,
252 ISCSI_NP_THREAD_INACTIVE = 2,
253 ISCSI_NP_THREAD_RESET = 3,
254 ISCSI_NP_THREAD_SHUTDOWN = 4,
255 ISCSI_NP_THREAD_EXIT = 5,
258 struct iscsi_conn_ops {
259 u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
260 u8 DataDigest; /* [0,1] == [None,CRC32C] */
261 u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
262 u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
264 * iSER specific connection parameters
266 u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
267 u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */
270 struct iscsi_sess_ops {
271 char InitiatorName[224];
272 char InitiatorAlias[256];
273 char TargetName[224];
274 char TargetAlias[256];
275 char TargetAddress[256];
276 u16 TargetPortalGroupTag; /* [0..65535] */
277 u16 MaxConnections; /* [1..65535] */
278 u8 InitialR2T; /* [0,1] == [No,Yes] */
279 u8 ImmediateData; /* [0,1] == [No,Yes] */
280 u32 MaxBurstLength; /* [512..2**24-1] */
281 u32 FirstBurstLength; /* [512..2**24-1] */
282 u16 DefaultTime2Wait; /* [0..3600] */
283 u16 DefaultTime2Retain; /* [0..3600] */
284 u16 MaxOutstandingR2T; /* [1..65535] */
285 u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
286 u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
287 u8 ErrorRecoveryLevel; /* [0..2] */
288 u8 SessionType; /* [0,1] == [Normal,Discovery]*/
290 * iSER specific session parameters
292 u8 RDMAExtensions; /* [0,1] == [No,Yes] */
295 struct iscsi_queue_req {
296 int state;
297 struct iscsi_cmd *cmd;
298 struct list_head qr_list;
301 struct iscsi_data_count {
302 int data_length;
303 int sync_and_steering;
304 enum data_count_type type;
305 u32 iov_count;
306 u32 ss_iov_count;
307 u32 ss_marker_count;
308 struct kvec *iov;
311 struct iscsi_param_list {
312 bool iser;
313 struct list_head param_list;
314 struct list_head extra_response_list;
317 struct iscsi_datain_req {
318 enum datain_req_comp_table dr_complete;
319 int generate_recovery_values;
320 enum datain_req_rec_table recovery;
321 u32 begrun;
322 u32 runlength;
323 u32 data_length;
324 u32 data_offset;
325 u32 data_sn;
326 u32 next_burst_len;
327 u32 read_data_done;
328 u32 seq_send_order;
329 struct list_head cmd_datain_node;
330 } ____cacheline_aligned;
332 struct iscsi_ooo_cmdsn {
333 u16 cid;
334 u32 batch_count;
335 u32 cmdsn;
336 u32 exp_cmdsn;
337 struct iscsi_cmd *cmd;
338 struct list_head ooo_list;
339 } ____cacheline_aligned;
341 struct iscsi_datain {
342 u8 flags;
343 u32 data_sn;
344 u32 length;
345 u32 offset;
346 } ____cacheline_aligned;
348 struct iscsi_r2t {
349 int seq_complete;
350 int recovery_r2t;
351 int sent_r2t;
352 u32 r2t_sn;
353 u32 offset;
354 u32 targ_xfer_tag;
355 u32 xfer_len;
356 struct list_head r2t_list;
357 } ____cacheline_aligned;
359 struct iscsi_cmd {
360 enum iscsi_timer_flags_table dataout_timer_flags;
361 /* DataOUT timeout retries */
362 u8 dataout_timeout_retries;
363 /* Within command recovery count */
364 u8 error_recovery_count;
365 /* iSCSI dependent state for out or order CmdSNs */
366 enum cmd_i_state_table deferred_i_state;
367 /* iSCSI dependent state */
368 enum cmd_i_state_table i_state;
369 /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
370 u8 immediate_cmd;
371 /* Immediate data present */
372 u8 immediate_data;
373 /* iSCSI Opcode */
374 u8 iscsi_opcode;
375 /* iSCSI Response Code */
376 u8 iscsi_response;
377 /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
378 u8 logout_reason;
379 /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
380 u8 logout_response;
381 /* MaxCmdSN has been incremented */
382 u8 maxcmdsn_inc;
383 /* Immediate Unsolicited Dataout */
384 u8 unsolicited_data;
385 /* Reject reason code */
386 u8 reject_reason;
387 /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
388 u16 logout_cid;
389 /* Command flags */
390 enum cmd_flags_table cmd_flags;
391 /* Initiator Task Tag assigned from Initiator */
392 itt_t init_task_tag;
393 /* Target Transfer Tag assigned from Target */
394 u32 targ_xfer_tag;
395 /* CmdSN assigned from Initiator */
396 u32 cmd_sn;
397 /* ExpStatSN assigned from Initiator */
398 u32 exp_stat_sn;
399 /* StatSN assigned to this ITT */
400 u32 stat_sn;
401 /* DataSN Counter */
402 u32 data_sn;
403 /* R2TSN Counter */
404 u32 r2t_sn;
405 /* Last DataSN acknowledged via DataAck SNACK */
406 u32 acked_data_sn;
407 /* Used for echoing NOPOUT ping data */
408 u32 buf_ptr_size;
409 /* Used to store DataDigest */
410 u32 data_crc;
411 /* Counter for MaxOutstandingR2T */
412 u32 outstanding_r2ts;
413 /* Next R2T Offset when DataSequenceInOrder=Yes */
414 u32 r2t_offset;
415 /* Iovec current and orig count for iscsi_cmd->iov_data */
416 u32 iov_data_count;
417 u32 orig_iov_data_count;
418 /* Number of miscellaneous iovecs used for IP stack calls */
419 u32 iov_misc_count;
420 /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */
421 u32 pdu_count;
422 /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */
423 u32 pdu_send_order;
424 /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */
425 u32 pdu_start;
426 /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */
427 u32 seq_send_order;
428 /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */
429 u32 seq_count;
430 /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */
431 u32 seq_no;
432 /* Lowest offset in current DataOUT sequence */
433 u32 seq_start_offset;
434 /* Highest offset in current DataOUT sequence */
435 u32 seq_end_offset;
436 /* Total size in bytes received so far of READ data */
437 u32 read_data_done;
438 /* Total size in bytes received so far of WRITE data */
439 u32 write_data_done;
440 /* Counter for FirstBurstLength key */
441 u32 first_burst_len;
442 /* Counter for MaxBurstLength key */
443 u32 next_burst_len;
444 /* Transfer size used for IP stack calls */
445 u32 tx_size;
446 /* Buffer used for various purposes */
447 void *buf_ptr;
448 /* Used by SendTargets=[iqn.,eui.] discovery */
449 void *text_in_ptr;
450 /* See include/linux/dma-mapping.h */
451 enum dma_data_direction data_direction;
452 /* iSCSI PDU Header + CRC */
453 unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
454 /* Number of times struct iscsi_cmd is present in immediate queue */
455 atomic_t immed_queue_count;
456 atomic_t response_queue_count;
457 spinlock_t datain_lock;
458 spinlock_t dataout_timeout_lock;
459 /* spinlock for protecting struct iscsi_cmd->i_state */
460 spinlock_t istate_lock;
461 /* spinlock for adding within command recovery entries */
462 spinlock_t error_lock;
463 /* spinlock for adding R2Ts */
464 spinlock_t r2t_lock;
465 /* DataIN List */
466 struct list_head datain_list;
467 /* R2T List */
468 struct list_head cmd_r2t_list;
469 /* Timer for DataOUT */
470 struct timer_list dataout_timer;
471 /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
472 struct kvec *iov_data;
473 /* Iovecs for miscellaneous purposes */
474 #define ISCSI_MISC_IOVECS 5
475 struct kvec iov_misc[ISCSI_MISC_IOVECS];
476 /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
477 struct iscsi_pdu *pdu_list;
478 /* Current struct iscsi_pdu used for DataPDUInOrder=No */
479 struct iscsi_pdu *pdu_ptr;
480 /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
481 struct iscsi_seq *seq_list;
482 /* Current struct iscsi_seq used for DataSequenceInOrder=No */
483 struct iscsi_seq *seq_ptr;
484 /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
485 struct iscsi_tmr_req *tmr_req;
486 /* Connection this command is alligient to */
487 struct iscsi_conn *conn;
488 /* Pointer to connection recovery entry */
489 struct iscsi_conn_recovery *cr;
490 /* Session the command is part of, used for connection recovery */
491 struct iscsi_session *sess;
492 /* list_head for connection list */
493 struct list_head i_conn_node;
494 /* The TCM I/O descriptor that is accessed via container_of() */
495 struct se_cmd se_cmd;
496 /* Sense buffer that will be mapped into outgoing status */
497 #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
498 unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN];
500 u32 padding;
501 u8 pad_bytes[4];
503 struct scatterlist *first_data_sg;
504 u32 first_data_sg_off;
505 u32 kmapped_nents;
506 sense_reason_t sense_reason;
507 } ____cacheline_aligned;
509 struct iscsi_tmr_req {
510 bool task_reassign:1;
511 u32 exp_data_sn;
512 struct iscsi_cmd *ref_cmd;
513 struct iscsi_conn_recovery *conn_recovery;
514 struct se_tmr_req *se_tmr_req;
517 struct iscsi_conn {
518 wait_queue_head_t queues_wq;
519 /* Authentication Successful for this connection */
520 u8 auth_complete;
521 /* State connection is currently in */
522 u8 conn_state;
523 u8 conn_logout_reason;
524 u8 network_transport;
525 enum iscsi_timer_flags_table nopin_timer_flags;
526 enum iscsi_timer_flags_table nopin_response_timer_flags;
527 /* Used to know what thread encountered a transport failure */
528 u8 which_thread;
529 /* connection id assigned by the Initiator */
530 u16 cid;
531 /* Remote TCP Port */
532 u16 login_port;
533 int net_size;
534 int login_family;
535 u32 auth_id;
536 u32 conn_flags;
537 /* Used for iscsi_tx_login_rsp() */
538 itt_t login_itt;
539 u32 exp_statsn;
540 /* Per connection status sequence number */
541 u32 stat_sn;
542 struct sockaddr_storage login_sockaddr;
543 struct sockaddr_storage local_sockaddr;
544 int conn_usage_count;
545 int conn_waiting_on_uc;
546 atomic_t check_immediate_queue;
547 atomic_t conn_logout_remove;
548 atomic_t connection_exit;
549 atomic_t connection_recovery;
550 atomic_t connection_reinstatement;
551 atomic_t connection_wait_rcfr;
552 atomic_t sleep_on_conn_wait_comp;
553 atomic_t transport_failed;
554 struct completion conn_post_wait_comp;
555 struct completion conn_wait_comp;
556 struct completion conn_wait_rcfr_comp;
557 struct completion conn_waiting_on_uc_comp;
558 struct completion conn_logout_comp;
559 struct completion tx_half_close_comp;
560 struct completion rx_half_close_comp;
561 /* socket used by this connection */
562 struct socket *sock;
563 void (*orig_data_ready)(struct sock *);
564 void (*orig_state_change)(struct sock *);
565 #define LOGIN_FLAGS_READ_ACTIVE 1
566 #define LOGIN_FLAGS_CLOSED 2
567 #define LOGIN_FLAGS_READY 4
568 #define LOGIN_FLAGS_INITIAL_PDU 8
569 unsigned long login_flags;
570 struct delayed_work login_work;
571 struct iscsi_login *login;
572 struct timer_list nopin_timer;
573 struct timer_list nopin_response_timer;
574 struct timer_list transport_timer;
575 struct task_struct *login_kworker;
576 /* Spinlock used for add/deleting cmd's from conn_cmd_list */
577 spinlock_t cmd_lock;
578 spinlock_t conn_usage_lock;
579 spinlock_t immed_queue_lock;
580 spinlock_t nopin_timer_lock;
581 spinlock_t response_queue_lock;
582 spinlock_t state_lock;
583 /* libcrypto RX and TX contexts for crc32c */
584 struct ahash_request *conn_rx_hash;
585 struct ahash_request *conn_tx_hash;
586 /* Used for scheduling TX and RX connection kthreads */
587 cpumask_var_t conn_cpumask;
588 unsigned int conn_rx_reset_cpumask:1;
589 unsigned int conn_tx_reset_cpumask:1;
590 /* list_head of struct iscsi_cmd for this connection */
591 struct list_head conn_cmd_list;
592 struct list_head immed_queue_list;
593 struct list_head response_queue_list;
594 struct iscsi_conn_ops *conn_ops;
595 struct iscsi_login *conn_login;
596 struct iscsit_transport *conn_transport;
597 struct iscsi_param_list *param_list;
598 /* Used for per connection auth state machine */
599 void *auth_protocol;
600 void *context;
601 struct iscsi_login_thread_s *login_thread;
602 struct iscsi_portal_group *tpg;
603 struct iscsi_tpg_np *tpg_np;
604 /* Pointer to parent session */
605 struct iscsi_session *sess;
606 int bitmap_id;
607 int rx_thread_active;
608 struct task_struct *rx_thread;
609 struct completion rx_login_comp;
610 int tx_thread_active;
611 struct task_struct *tx_thread;
612 /* list_head for session connection list */
613 struct list_head conn_list;
614 } ____cacheline_aligned;
616 struct iscsi_conn_recovery {
617 u16 cid;
618 u32 cmd_count;
619 u32 maxrecvdatasegmentlength;
620 u32 maxxmitdatasegmentlength;
621 int ready_for_reallegiance;
622 struct list_head conn_recovery_cmd_list;
623 spinlock_t conn_recovery_cmd_lock;
624 struct timer_list time2retain_timer;
625 struct iscsi_session *sess;
626 struct list_head cr_list;
627 } ____cacheline_aligned;
629 struct iscsi_session {
630 u8 initiator_vendor;
631 u8 isid[6];
632 enum iscsi_timer_flags_table time2retain_timer_flags;
633 u8 version_active;
634 u16 cid_called;
635 u16 conn_recovery_count;
636 u16 tsih;
637 /* state session is currently in */
638 u32 session_state;
639 /* session wide counter: initiator assigned task tag */
640 itt_t init_task_tag;
641 /* session wide counter: target assigned task tag */
642 u32 targ_xfer_tag;
643 u32 cmdsn_window;
645 /* protects cmdsn values */
646 struct mutex cmdsn_mutex;
647 /* session wide counter: expected command sequence number */
648 u32 exp_cmd_sn;
649 /* session wide counter: maximum allowed command sequence number */
650 atomic_t max_cmd_sn;
651 struct list_head sess_ooo_cmdsn_list;
653 /* LIO specific session ID */
654 u32 sid;
655 char auth_type[8];
656 /* unique within the target */
657 int session_index;
658 /* Used for session reference counting */
659 int session_usage_count;
660 int session_waiting_on_uc;
661 atomic_long_t cmd_pdus;
662 atomic_long_t rsp_pdus;
663 atomic_long_t tx_data_octets;
664 atomic_long_t rx_data_octets;
665 atomic_long_t conn_digest_errors;
666 atomic_long_t conn_timeout_errors;
667 u64 creation_time;
668 /* Number of active connections */
669 atomic_t nconn;
670 atomic_t session_continuation;
671 atomic_t session_fall_back_to_erl0;
672 atomic_t session_logout;
673 atomic_t session_reinstatement;
674 atomic_t session_stop_active;
675 atomic_t sleep_on_sess_wait_comp;
676 /* connection list */
677 struct list_head sess_conn_list;
678 struct list_head cr_active_list;
679 struct list_head cr_inactive_list;
680 spinlock_t conn_lock;
681 spinlock_t cr_a_lock;
682 spinlock_t cr_i_lock;
683 spinlock_t session_usage_lock;
684 spinlock_t ttt_lock;
685 struct completion async_msg_comp;
686 struct completion reinstatement_comp;
687 struct completion session_wait_comp;
688 struct completion session_waiting_on_uc_comp;
689 struct timer_list time2retain_timer;
690 struct iscsi_sess_ops *sess_ops;
691 struct se_session *se_sess;
692 struct iscsi_portal_group *tpg;
693 } ____cacheline_aligned;
695 struct iscsi_login {
696 u8 auth_complete;
697 u8 checked_for_existing;
698 u8 current_stage;
699 u8 leading_connection;
700 u8 first_request;
701 u8 version_min;
702 u8 version_max;
703 u8 login_complete;
704 u8 login_failed;
705 bool zero_tsih;
706 char isid[6];
707 u32 cmd_sn;
708 itt_t init_task_tag;
709 u32 initial_exp_statsn;
710 u32 rsp_length;
711 u16 cid;
712 u16 tsih;
713 char req[ISCSI_HDR_LEN];
714 char rsp[ISCSI_HDR_LEN];
715 char *req_buf;
716 char *rsp_buf;
717 struct iscsi_conn *conn;
718 struct iscsi_np *np;
719 } ____cacheline_aligned;
721 struct iscsi_node_attrib {
722 u32 dataout_timeout;
723 u32 dataout_timeout_retries;
724 u32 default_erl;
725 u32 nopin_timeout;
726 u32 nopin_response_timeout;
727 u32 random_datain_pdu_offsets;
728 u32 random_datain_seq_offsets;
729 u32 random_r2t_offsets;
730 u32 tmr_cold_reset;
731 u32 tmr_warm_reset;
732 struct iscsi_node_acl *nacl;
735 struct se_dev_entry_s;
737 struct iscsi_node_auth {
738 enum naf_flags_table naf_flags;
739 int authenticate_target;
740 /* Used for iscsit_global->discovery_auth,
741 * set to zero (auth disabled) by default */
742 int enforce_discovery_auth;
743 #define MAX_USER_LEN 256
744 #define MAX_PASS_LEN 256
745 char userid[MAX_USER_LEN];
746 char password[MAX_PASS_LEN];
747 char userid_mutual[MAX_USER_LEN];
748 char password_mutual[MAX_PASS_LEN];
751 #include "iscsi_target_stat.h"
753 struct iscsi_node_stat_grps {
754 struct config_group iscsi_sess_stats_group;
755 struct config_group iscsi_conn_stats_group;
758 struct iscsi_node_acl {
759 struct se_node_acl se_node_acl;
760 struct iscsi_node_attrib node_attrib;
761 struct iscsi_node_auth node_auth;
762 struct iscsi_node_stat_grps node_stat_grps;
765 struct iscsi_tpg_attrib {
766 u32 authentication;
767 u32 login_timeout;
768 u32 netif_timeout;
769 u32 generate_node_acls;
770 u32 cache_dynamic_acls;
771 u32 default_cmdsn_depth;
772 u32 demo_mode_write_protect;
773 u32 prod_mode_write_protect;
774 u32 demo_mode_discovery;
775 u32 default_erl;
776 u8 t10_pi;
777 u32 fabric_prot_type;
778 u32 tpg_enabled_sendtargets;
779 u32 login_keys_workaround;
780 struct iscsi_portal_group *tpg;
783 struct iscsi_np {
784 int np_network_transport;
785 int np_ip_proto;
786 int np_sock_type;
787 enum np_thread_state_table np_thread_state;
788 bool enabled;
789 atomic_t np_reset_count;
790 enum iscsi_timer_flags_table np_login_timer_flags;
791 u32 np_exports;
792 enum np_flags_table np_flags;
793 spinlock_t np_thread_lock;
794 struct completion np_restart_comp;
795 struct socket *np_socket;
796 struct sockaddr_storage np_sockaddr;
797 struct task_struct *np_thread;
798 struct timer_list np_login_timer;
799 void *np_context;
800 struct iscsit_transport *np_transport;
801 struct list_head np_list;
802 } ____cacheline_aligned;
804 struct iscsi_tpg_np {
805 struct iscsi_np *tpg_np;
806 struct iscsi_portal_group *tpg;
807 struct iscsi_tpg_np *tpg_np_parent;
808 struct list_head tpg_np_list;
809 struct list_head tpg_np_child_list;
810 struct list_head tpg_np_parent_list;
811 struct se_tpg_np se_tpg_np;
812 spinlock_t tpg_np_parent_lock;
813 struct completion tpg_np_comp;
814 struct kref tpg_np_kref;
817 struct iscsi_portal_group {
818 unsigned char tpg_chap_id;
819 /* TPG State */
820 enum tpg_state_table tpg_state;
821 /* Target Portal Group Tag */
822 u16 tpgt;
823 /* Id assigned to target sessions */
824 u16 ntsih;
825 /* Number of active sessions */
826 u32 nsessions;
827 /* Number of Network Portals available for this TPG */
828 u32 num_tpg_nps;
829 /* Per TPG LIO specific session ID. */
830 u32 sid;
831 /* Spinlock for adding/removing Network Portals */
832 spinlock_t tpg_np_lock;
833 spinlock_t tpg_state_lock;
834 struct se_portal_group tpg_se_tpg;
835 struct mutex tpg_access_lock;
836 struct semaphore np_login_sem;
837 struct iscsi_tpg_attrib tpg_attrib;
838 struct iscsi_node_auth tpg_demo_auth;
839 /* Pointer to default list of iSCSI parameters for TPG */
840 struct iscsi_param_list *param_list;
841 struct iscsi_tiqn *tpg_tiqn;
842 struct list_head tpg_gnp_list;
843 struct list_head tpg_list;
844 } ____cacheline_aligned;
846 struct iscsi_wwn_stat_grps {
847 struct config_group iscsi_stat_group;
848 struct config_group iscsi_instance_group;
849 struct config_group iscsi_sess_err_group;
850 struct config_group iscsi_tgt_attr_group;
851 struct config_group iscsi_login_stats_group;
852 struct config_group iscsi_logout_stats_group;
855 struct iscsi_tiqn {
856 #define ISCSI_IQN_LEN 224
857 unsigned char tiqn[ISCSI_IQN_LEN];
858 enum tiqn_state_table tiqn_state;
859 int tiqn_access_count;
860 u32 tiqn_active_tpgs;
861 u32 tiqn_ntpgs;
862 u32 tiqn_num_tpg_nps;
863 u32 tiqn_nsessions;
864 struct list_head tiqn_list;
865 struct list_head tiqn_tpg_list;
866 spinlock_t tiqn_state_lock;
867 spinlock_t tiqn_tpg_lock;
868 struct se_wwn tiqn_wwn;
869 struct iscsi_wwn_stat_grps tiqn_stat_grps;
870 int tiqn_index;
871 struct iscsi_sess_err_stats sess_err_stats;
872 struct iscsi_login_stats login_stats;
873 struct iscsi_logout_stats logout_stats;
874 } ____cacheline_aligned;
876 struct iscsit_global {
877 /* In core shutdown */
878 u32 in_shutdown;
879 u32 active_ts;
880 /* Unique identifier used for the authentication daemon */
881 u32 auth_id;
882 u32 inactive_ts;
883 #define ISCSIT_BITMAP_BITS 262144
884 /* Thread Set bitmap pointer */
885 unsigned long *ts_bitmap;
886 spinlock_t ts_bitmap_lock;
887 /* Used for iSCSI discovery session authentication */
888 struct iscsi_node_acl discovery_acl;
889 struct iscsi_portal_group *discovery_tpg;
892 static inline u32 session_get_next_ttt(struct iscsi_session *session)
894 u32 ttt;
896 spin_lock_bh(&session->ttt_lock);
897 ttt = session->targ_xfer_tag++;
898 if (ttt == 0xFFFFFFFF)
899 ttt = session->targ_xfer_tag++;
900 spin_unlock_bh(&session->ttt_lock);
902 return ttt;
905 extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t);
907 static inline void iscsit_thread_check_cpumask(
908 struct iscsi_conn *conn,
909 struct task_struct *p,
910 int mode)
913 * mode == 1 signals iscsi_target_tx_thread() usage.
914 * mode == 0 signals iscsi_target_rx_thread() usage.
916 if (mode == 1) {
917 if (!conn->conn_tx_reset_cpumask)
918 return;
919 conn->conn_tx_reset_cpumask = 0;
920 } else {
921 if (!conn->conn_rx_reset_cpumask)
922 return;
923 conn->conn_rx_reset_cpumask = 0;
926 * Update the CPU mask for this single kthread so that
927 * both TX and RX kthreads are scheduled to run on the
928 * same CPU.
930 set_cpus_allowed_ptr(p, conn->conn_cpumask);
932 #endif /* ISCSI_TARGET_CORE_H */