PageRenderTime 38ms CodeModel.GetById 11ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/target/iscsi/iscsi_target_core.h

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