1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2e48354ceSNicholas Bellinger #ifndef ISCSI_TARGET_CORE_H
3e48354ceSNicholas Bellinger #define ISCSI_TARGET_CORE_H
4e48354ceSNicholas Bellinger
58dcf07beSBart Van Assche #include <linux/dma-direction.h> /* enum dma_data_direction */
68dcf07beSBart Van Assche #include <linux/list.h> /* struct list_head */
710e9cbb6SMatthew Wilcox #include <linux/sched.h>
88dcf07beSBart Van Assche #include <linux/socket.h> /* struct sockaddr_storage */
98dcf07beSBart Van Assche #include <linux/types.h> /* u8 */
108dcf07beSBart Van Assche #include <scsi/iscsi_proto.h> /* itt_t */
118dcf07beSBart Van Assche #include <target/target_core_base.h> /* struct se_cmd */
128dcf07beSBart Van Assche
138dcf07beSBart Van Assche struct sock;
14e48354ceSNicholas Bellinger
152999ee7fSNicholas Bellinger #define ISCSIT_VERSION "v4.1.0"
16e48354ceSNicholas Bellinger #define ISCSI_MAX_DATASN_MISSING_COUNT 16
17e48354ceSNicholas Bellinger #define ISCSI_TX_THREAD_TCP_TIMEOUT 2
18e48354ceSNicholas Bellinger #define ISCSI_RX_THREAD_TCP_TIMEOUT 2
19e48354ceSNicholas Bellinger #define SECONDS_FOR_ASYNC_LOGOUT 10
20e48354ceSNicholas Bellinger #define SECONDS_FOR_ASYNC_TEXT 10
21e48354ceSNicholas Bellinger #define SECONDS_FOR_LOGOUT_COMP 15
22e48354ceSNicholas Bellinger #define WHITE_SPACE " \t\v\f\n\r"
23988e3a85SNicholas Bellinger #define ISCSIT_MIN_TAGS 16
24988e3a85SNicholas Bellinger #define ISCSIT_EXTRA_TAGS 8
25837f6452SNicholas Bellinger #define ISCSIT_TCP_BACKLOG 256
26073900bdSNicholas Bellinger #define ISCSI_RX_THREAD_NAME "iscsi_trx"
27073900bdSNicholas Bellinger #define ISCSI_TX_THREAD_NAME "iscsi_ttx"
28df711553SDavid Disseldorp #define ISCSI_IQN_LEN 224
29a6e0d179SDmitry Bogdanov #define NA_AUTHENTICATION_INHERITED -1
30e48354ceSNicholas Bellinger
31e48354ceSNicholas Bellinger /* struct iscsi_node_attrib sanity values */
32e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT 3
33e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT_MAX 60
34e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT_MIX 2
35e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT_RETRIES 5
36e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15
37e48354ceSNicholas Bellinger #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1
38cf0eb28dSNicholas Bellinger #define NA_NOPIN_TIMEOUT 15
39e48354ceSNicholas Bellinger #define NA_NOPIN_TIMEOUT_MAX 60
40e48354ceSNicholas Bellinger #define NA_NOPIN_TIMEOUT_MIN 3
41cf0eb28dSNicholas Bellinger #define NA_NOPIN_RESPONSE_TIMEOUT 30
42e48354ceSNicholas Bellinger #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60
43e48354ceSNicholas Bellinger #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3
44e48354ceSNicholas Bellinger #define NA_RANDOM_DATAIN_PDU_OFFSETS 0
45e48354ceSNicholas Bellinger #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0
46e48354ceSNicholas Bellinger #define NA_RANDOM_R2T_OFFSETS 0
47e48354ceSNicholas Bellinger
48e48354ceSNicholas Bellinger /* struct iscsi_tpg_attrib sanity values */
49e48354ceSNicholas Bellinger #define TA_AUTHENTICATION 1
50e48354ceSNicholas Bellinger #define TA_LOGIN_TIMEOUT 15
51e48354ceSNicholas Bellinger #define TA_LOGIN_TIMEOUT_MAX 30
52e48354ceSNicholas Bellinger #define TA_LOGIN_TIMEOUT_MIN 5
53e48354ceSNicholas Bellinger #define TA_GENERATE_NODE_ACLS 0
5438f7d6edSNicholas Bellinger #define TA_DEFAULT_CMDSN_DEPTH 64
55e48354ceSNicholas Bellinger #define TA_DEFAULT_CMDSN_DEPTH_MAX 512
56e48354ceSNicholas Bellinger #define TA_DEFAULT_CMDSN_DEPTH_MIN 1
57e48354ceSNicholas Bellinger #define TA_CACHE_DYNAMIC_ACLS 0
58e48354ceSNicholas Bellinger /* Enabled by default in demo mode (generic_node_acls=1) */
59e48354ceSNicholas Bellinger #define TA_DEMO_MODE_WRITE_PROTECT 1
60e48354ceSNicholas Bellinger /* Disabled by default in production mode w/ explict ACLs */
61e48354ceSNicholas Bellinger #define TA_PROD_MODE_WRITE_PROTECT 0
624c54b6cfSThomas Glanzmann #define TA_DEMO_MODE_DISCOVERY 1
63d1fa7a1dSNicholas Bellinger #define TA_DEFAULT_ERL 0
64e48354ceSNicholas Bellinger #define TA_CACHE_CORE_NPS 0
655b168dcdSSagi Grimberg /* T10 protection information disabled by default */
665b168dcdSSagi Grimberg #define TA_DEFAULT_T10_PI 0
67901c04a3SNicholas Bellinger #define TA_DEFAULT_FABRIC_PROT_TYPE 0
68a6415cddSDavid Disseldorp /* TPG status needs to be enabled to return sendtargets discovery endpoint info */
69a6415cddSDavid Disseldorp #define TA_DEFAULT_TPG_ENABLED_SENDTARGETS 1
70138d351eSNicholas Bellinger /*
71138d351eSNicholas Bellinger * Used to control the sending of keys with optional to respond state bit,
72138d351eSNicholas Bellinger * as a workaround for non RFC compliant initiators,that do not propose,
73138d351eSNicholas Bellinger * nor respond to specific keys required for login to complete.
74138d351eSNicholas Bellinger *
75138d351eSNicholas Bellinger * See iscsi_check_proposer_for_optional_reply() for more details.
76138d351eSNicholas Bellinger */
77138d351eSNicholas Bellinger #define TA_DEFAULT_LOGIN_KEYS_WORKAROUND 1
78c0427f15SChristoph Hellwig
79c0427f15SChristoph Hellwig #define ISCSI_IOV_DATA_BUFFER 5
80c0427f15SChristoph Hellwig
81baa4d64bSNicholas Bellinger enum iscsit_transport_type {
82e48354ceSNicholas Bellinger ISCSI_TCP = 0,
83e48354ceSNicholas Bellinger ISCSI_SCTP_TCP = 1,
84e48354ceSNicholas Bellinger ISCSI_SCTP_UDP = 2,
85e48354ceSNicholas Bellinger ISCSI_IWARP_TCP = 3,
86e48354ceSNicholas Bellinger ISCSI_IWARP_SCTP = 4,
87e48354ceSNicholas Bellinger ISCSI_INFINIBAND = 5,
88ff7199b0SNicholas Bellinger ISCSI_CXGBIT = 6,
89e48354ceSNicholas Bellinger };
90e48354ceSNicholas Bellinger
91e48354ceSNicholas Bellinger /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */
92e48354ceSNicholas Bellinger enum target_conn_state_table {
93e48354ceSNicholas Bellinger TARG_CONN_STATE_FREE = 0x1,
94e48354ceSNicholas Bellinger TARG_CONN_STATE_XPT_UP = 0x3,
95e48354ceSNicholas Bellinger TARG_CONN_STATE_IN_LOGIN = 0x4,
96e48354ceSNicholas Bellinger TARG_CONN_STATE_LOGGED_IN = 0x5,
97e48354ceSNicholas Bellinger TARG_CONN_STATE_IN_LOGOUT = 0x6,
98e48354ceSNicholas Bellinger TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7,
99e48354ceSNicholas Bellinger TARG_CONN_STATE_CLEANUP_WAIT = 0x8,
100e48354ceSNicholas Bellinger };
101e48354ceSNicholas Bellinger
102e48354ceSNicholas Bellinger /* RFC-3720 7.3.2 Session State Diagram for a Target */
103e48354ceSNicholas Bellinger enum target_sess_state_table {
104e48354ceSNicholas Bellinger TARG_SESS_STATE_FREE = 0x1,
105e48354ceSNicholas Bellinger TARG_SESS_STATE_ACTIVE = 0x2,
106e48354ceSNicholas Bellinger TARG_SESS_STATE_LOGGED_IN = 0x3,
107e48354ceSNicholas Bellinger TARG_SESS_STATE_FAILED = 0x4,
108e48354ceSNicholas Bellinger TARG_SESS_STATE_IN_CONTINUE = 0x5,
109e48354ceSNicholas Bellinger };
110e48354ceSNicholas Bellinger
111e48354ceSNicholas Bellinger /* struct iscsi_data_count->type */
112e48354ceSNicholas Bellinger enum data_count_type {
113e48354ceSNicholas Bellinger ISCSI_RX_DATA = 1,
114e48354ceSNicholas Bellinger ISCSI_TX_DATA = 2,
115e48354ceSNicholas Bellinger };
116e48354ceSNicholas Bellinger
117e48354ceSNicholas Bellinger /* struct iscsi_datain_req->dr_complete */
118e48354ceSNicholas Bellinger enum datain_req_comp_table {
119e48354ceSNicholas Bellinger DATAIN_COMPLETE_NORMAL = 1,
120e48354ceSNicholas Bellinger DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2,
121e48354ceSNicholas Bellinger DATAIN_COMPLETE_CONNECTION_RECOVERY = 3,
122e48354ceSNicholas Bellinger };
123e48354ceSNicholas Bellinger
124e48354ceSNicholas Bellinger /* struct iscsi_datain_req->recovery */
125e48354ceSNicholas Bellinger enum datain_req_rec_table {
126e48354ceSNicholas Bellinger DATAIN_WITHIN_COMMAND_RECOVERY = 1,
127e48354ceSNicholas Bellinger DATAIN_CONNECTION_RECOVERY = 2,
128e48354ceSNicholas Bellinger };
129e48354ceSNicholas Bellinger
130e48354ceSNicholas Bellinger /* struct iscsi_portal_group->state */
131e48354ceSNicholas Bellinger enum tpg_state_table {
132e48354ceSNicholas Bellinger TPG_STATE_FREE = 0,
133e48354ceSNicholas Bellinger TPG_STATE_ACTIVE = 1,
134e48354ceSNicholas Bellinger TPG_STATE_INACTIVE = 2,
135e48354ceSNicholas Bellinger TPG_STATE_COLD_RESET = 3,
136e48354ceSNicholas Bellinger };
137e48354ceSNicholas Bellinger
138e48354ceSNicholas Bellinger /* struct iscsi_tiqn->tiqn_state */
139e48354ceSNicholas Bellinger enum tiqn_state_table {
140e48354ceSNicholas Bellinger TIQN_STATE_ACTIVE = 1,
141e48354ceSNicholas Bellinger TIQN_STATE_SHUTDOWN = 2,
142e48354ceSNicholas Bellinger };
143e48354ceSNicholas Bellinger
14466cd9d4eSMax Gurtovoy /* struct iscsit_cmd->cmd_flags */
145e48354ceSNicholas Bellinger enum cmd_flags_table {
146e48354ceSNicholas Bellinger ICF_GOT_LAST_DATAOUT = 0x00000001,
147e48354ceSNicholas Bellinger ICF_GOT_DATACK_SNACK = 0x00000002,
148e48354ceSNicholas Bellinger ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004,
149e48354ceSNicholas Bellinger ICF_SENT_LAST_R2T = 0x00000008,
150e48354ceSNicholas Bellinger ICF_WITHIN_COMMAND_RECOVERY = 0x00000010,
151e48354ceSNicholas Bellinger ICF_CONTIG_MEMORY = 0x00000020,
152e48354ceSNicholas Bellinger ICF_ATTACHED_TO_RQUEUE = 0x00000040,
153e48354ceSNicholas Bellinger ICF_OOO_CMDSN = 0x00000080,
1548060b8ddSAndy Grover ICF_SENDTARGETS_ALL = 0x00000100,
1558060b8ddSAndy Grover ICF_SENDTARGETS_SINGLE = 0x00000200,
156e48354ceSNicholas Bellinger };
157e48354ceSNicholas Bellinger
15866cd9d4eSMax Gurtovoy /* struct iscsit_cmd->i_state */
159e48354ceSNicholas Bellinger enum cmd_i_state_table {
160e48354ceSNicholas Bellinger ISTATE_NO_STATE = 0,
161e48354ceSNicholas Bellinger ISTATE_NEW_CMD = 1,
162e48354ceSNicholas Bellinger ISTATE_DEFERRED_CMD = 2,
163e48354ceSNicholas Bellinger ISTATE_UNSOLICITED_DATA = 3,
164e48354ceSNicholas Bellinger ISTATE_RECEIVE_DATAOUT = 4,
165e48354ceSNicholas Bellinger ISTATE_RECEIVE_DATAOUT_RECOVERY = 5,
166e48354ceSNicholas Bellinger ISTATE_RECEIVED_LAST_DATAOUT = 6,
167e48354ceSNicholas Bellinger ISTATE_WITHIN_DATAOUT_RECOVERY = 7,
168e48354ceSNicholas Bellinger ISTATE_IN_CONNECTION_RECOVERY = 8,
169e48354ceSNicholas Bellinger ISTATE_RECEIVED_TASKMGT = 9,
170e48354ceSNicholas Bellinger ISTATE_SEND_ASYNCMSG = 10,
171e48354ceSNicholas Bellinger ISTATE_SENT_ASYNCMSG = 11,
172e48354ceSNicholas Bellinger ISTATE_SEND_DATAIN = 12,
173e48354ceSNicholas Bellinger ISTATE_SEND_LAST_DATAIN = 13,
174e48354ceSNicholas Bellinger ISTATE_SENT_LAST_DATAIN = 14,
175e48354ceSNicholas Bellinger ISTATE_SEND_LOGOUTRSP = 15,
176e48354ceSNicholas Bellinger ISTATE_SENT_LOGOUTRSP = 16,
177e48354ceSNicholas Bellinger ISTATE_SEND_NOPIN = 17,
178e48354ceSNicholas Bellinger ISTATE_SENT_NOPIN = 18,
179e48354ceSNicholas Bellinger ISTATE_SEND_REJECT = 19,
180e48354ceSNicholas Bellinger ISTATE_SENT_REJECT = 20,
181e48354ceSNicholas Bellinger ISTATE_SEND_R2T = 21,
182e48354ceSNicholas Bellinger ISTATE_SENT_R2T = 22,
183e48354ceSNicholas Bellinger ISTATE_SEND_R2T_RECOVERY = 23,
184e48354ceSNicholas Bellinger ISTATE_SENT_R2T_RECOVERY = 24,
185e48354ceSNicholas Bellinger ISTATE_SEND_LAST_R2T = 25,
186e48354ceSNicholas Bellinger ISTATE_SENT_LAST_R2T = 26,
187e48354ceSNicholas Bellinger ISTATE_SEND_LAST_R2T_RECOVERY = 27,
188e48354ceSNicholas Bellinger ISTATE_SENT_LAST_R2T_RECOVERY = 28,
189e48354ceSNicholas Bellinger ISTATE_SEND_STATUS = 29,
190e48354ceSNicholas Bellinger ISTATE_SEND_STATUS_BROKEN_PC = 30,
191e48354ceSNicholas Bellinger ISTATE_SENT_STATUS = 31,
192e48354ceSNicholas Bellinger ISTATE_SEND_STATUS_RECOVERY = 32,
193e48354ceSNicholas Bellinger ISTATE_SENT_STATUS_RECOVERY = 33,
194e48354ceSNicholas Bellinger ISTATE_SEND_TASKMGTRSP = 34,
195e48354ceSNicholas Bellinger ISTATE_SENT_TASKMGTRSP = 35,
196e48354ceSNicholas Bellinger ISTATE_SEND_TEXTRSP = 36,
197e48354ceSNicholas Bellinger ISTATE_SENT_TEXTRSP = 37,
198e48354ceSNicholas Bellinger ISTATE_SEND_NOPIN_WANT_RESPONSE = 38,
199e48354ceSNicholas Bellinger ISTATE_SENT_NOPIN_WANT_RESPONSE = 39,
200e48354ceSNicholas Bellinger ISTATE_SEND_NOPIN_NO_RESPONSE = 40,
201e48354ceSNicholas Bellinger ISTATE_REMOVE = 41,
202e48354ceSNicholas Bellinger ISTATE_FREE = 42,
203e48354ceSNicholas Bellinger };
204e48354ceSNicholas Bellinger
205e48354ceSNicholas Bellinger /* Used for iscsi_recover_cmdsn() return values */
206e48354ceSNicholas Bellinger enum recover_cmdsn_ret_table {
207e48354ceSNicholas Bellinger CMDSN_ERROR_CANNOT_RECOVER = -1,
208e48354ceSNicholas Bellinger CMDSN_NORMAL_OPERATION = 0,
209e48354ceSNicholas Bellinger CMDSN_LOWER_THAN_EXP = 1,
210e48354ceSNicholas Bellinger CMDSN_HIGHER_THAN_EXP = 2,
211ea7e32beSNicholas Bellinger CMDSN_MAXCMDSN_OVERRUN = 3,
212e48354ceSNicholas Bellinger };
213e48354ceSNicholas Bellinger
214e48354ceSNicholas Bellinger /* Used for iscsi_handle_immediate_data() return values */
215e48354ceSNicholas Bellinger enum immedate_data_ret_table {
216e48354ceSNicholas Bellinger IMMEDIATE_DATA_CANNOT_RECOVER = -1,
217e48354ceSNicholas Bellinger IMMEDIATE_DATA_NORMAL_OPERATION = 0,
218e48354ceSNicholas Bellinger IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1,
219e48354ceSNicholas Bellinger };
220e48354ceSNicholas Bellinger
221e48354ceSNicholas Bellinger /* Used for iscsi_decide_dataout_action() return values */
222e48354ceSNicholas Bellinger enum dataout_action_ret_table {
223e48354ceSNicholas Bellinger DATAOUT_CANNOT_RECOVER = -1,
224e48354ceSNicholas Bellinger DATAOUT_NORMAL = 0,
225e48354ceSNicholas Bellinger DATAOUT_SEND_R2T = 1,
226e48354ceSNicholas Bellinger DATAOUT_SEND_TO_TRANSPORT = 2,
227e48354ceSNicholas Bellinger DATAOUT_WITHIN_COMMAND_RECOVERY = 3,
228e48354ceSNicholas Bellinger };
229e48354ceSNicholas Bellinger
230e48354ceSNicholas Bellinger /* Used for struct iscsi_node_auth->naf_flags */
231e48354ceSNicholas Bellinger enum naf_flags_table {
232e48354ceSNicholas Bellinger NAF_USERID_SET = 0x01,
233e48354ceSNicholas Bellinger NAF_PASSWORD_SET = 0x02,
234e48354ceSNicholas Bellinger NAF_USERID_IN_SET = 0x04,
235e48354ceSNicholas Bellinger NAF_PASSWORD_IN_SET = 0x08,
236e48354ceSNicholas Bellinger };
237e48354ceSNicholas Bellinger
238e48354ceSNicholas Bellinger /* Used by various struct timer_list to manage iSCSI specific state */
239e48354ceSNicholas Bellinger enum iscsi_timer_flags_table {
240e48354ceSNicholas Bellinger ISCSI_TF_RUNNING = 0x01,
241e48354ceSNicholas Bellinger ISCSI_TF_STOP = 0x02,
242e48354ceSNicholas Bellinger ISCSI_TF_EXPIRED = 0x04,
243e48354ceSNicholas Bellinger };
244e48354ceSNicholas Bellinger
245e48354ceSNicholas Bellinger /* Used for struct iscsi_np->np_flags */
246e48354ceSNicholas Bellinger enum np_flags_table {
247e48354ceSNicholas Bellinger NPF_IP_NETWORK = 0x00,
248e48354ceSNicholas Bellinger };
249e48354ceSNicholas Bellinger
250e48354ceSNicholas Bellinger /* Used for struct iscsi_np->np_thread_state */
251e48354ceSNicholas Bellinger enum np_thread_state_table {
252e48354ceSNicholas Bellinger ISCSI_NP_THREAD_ACTIVE = 1,
253e48354ceSNicholas Bellinger ISCSI_NP_THREAD_INACTIVE = 2,
254e48354ceSNicholas Bellinger ISCSI_NP_THREAD_RESET = 3,
255e48354ceSNicholas Bellinger ISCSI_NP_THREAD_SHUTDOWN = 4,
256e48354ceSNicholas Bellinger ISCSI_NP_THREAD_EXIT = 5,
257e48354ceSNicholas Bellinger };
258e48354ceSNicholas Bellinger
259e48354ceSNicholas Bellinger struct iscsi_conn_ops {
260e48354ceSNicholas Bellinger u8 HeaderDigest; /* [0,1] == [None,CRC32C] */
261e48354ceSNicholas Bellinger u8 DataDigest; /* [0,1] == [None,CRC32C] */
262e48354ceSNicholas Bellinger u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */
263e004cb25SNicholas Bellinger u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */
26403aa2070SNicholas Bellinger /*
26503aa2070SNicholas Bellinger * iSER specific connection parameters
26603aa2070SNicholas Bellinger */
26703aa2070SNicholas Bellinger u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */
26803aa2070SNicholas Bellinger u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */
269e48354ceSNicholas Bellinger };
270e48354ceSNicholas Bellinger
271e48354ceSNicholas Bellinger struct iscsi_sess_ops {
272df711553SDavid Disseldorp char InitiatorName[ISCSI_IQN_LEN];
273e48354ceSNicholas Bellinger char InitiatorAlias[256];
274df711553SDavid Disseldorp char TargetName[ISCSI_IQN_LEN];
275e48354ceSNicholas Bellinger char TargetAlias[256];
276e48354ceSNicholas Bellinger char TargetAddress[256];
277e48354ceSNicholas Bellinger u16 TargetPortalGroupTag; /* [0..65535] */
278e48354ceSNicholas Bellinger u16 MaxConnections; /* [1..65535] */
279e48354ceSNicholas Bellinger u8 InitialR2T; /* [0,1] == [No,Yes] */
280e48354ceSNicholas Bellinger u8 ImmediateData; /* [0,1] == [No,Yes] */
281e48354ceSNicholas Bellinger u32 MaxBurstLength; /* [512..2**24-1] */
282e48354ceSNicholas Bellinger u32 FirstBurstLength; /* [512..2**24-1] */
283e48354ceSNicholas Bellinger u16 DefaultTime2Wait; /* [0..3600] */
284e48354ceSNicholas Bellinger u16 DefaultTime2Retain; /* [0..3600] */
285e48354ceSNicholas Bellinger u16 MaxOutstandingR2T; /* [1..65535] */
286e48354ceSNicholas Bellinger u8 DataPDUInOrder; /* [0,1] == [No,Yes] */
287e48354ceSNicholas Bellinger u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */
288e48354ceSNicholas Bellinger u8 ErrorRecoveryLevel; /* [0..2] */
289e48354ceSNicholas Bellinger u8 SessionType; /* [0,1] == [Normal,Discovery]*/
29003aa2070SNicholas Bellinger /*
29103aa2070SNicholas Bellinger * iSER specific session parameters
29203aa2070SNicholas Bellinger */
29303aa2070SNicholas Bellinger u8 RDMAExtensions; /* [0,1] == [No,Yes] */
294e48354ceSNicholas Bellinger };
295e48354ceSNicholas Bellinger
296e48354ceSNicholas Bellinger struct iscsi_queue_req {
297e48354ceSNicholas Bellinger int state;
29866cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd;
299e48354ceSNicholas Bellinger struct list_head qr_list;
300e48354ceSNicholas Bellinger };
301e48354ceSNicholas Bellinger
302e48354ceSNicholas Bellinger struct iscsi_param_list {
30303aa2070SNicholas Bellinger bool iser;
304e48354ceSNicholas Bellinger struct list_head param_list;
305e48354ceSNicholas Bellinger struct list_head extra_response_list;
306e48354ceSNicholas Bellinger };
307e48354ceSNicholas Bellinger
308e48354ceSNicholas Bellinger struct iscsi_datain_req {
309e48354ceSNicholas Bellinger enum datain_req_comp_table dr_complete;
310e48354ceSNicholas Bellinger int generate_recovery_values;
311e48354ceSNicholas Bellinger enum datain_req_rec_table recovery;
312e48354ceSNicholas Bellinger u32 begrun;
313e48354ceSNicholas Bellinger u32 runlength;
314e48354ceSNicholas Bellinger u32 data_length;
315e48354ceSNicholas Bellinger u32 data_offset;
316e48354ceSNicholas Bellinger u32 data_sn;
317e48354ceSNicholas Bellinger u32 next_burst_len;
318e48354ceSNicholas Bellinger u32 read_data_done;
319e48354ceSNicholas Bellinger u32 seq_send_order;
3208b1e1244SAndy Grover struct list_head cmd_datain_node;
321e48354ceSNicholas Bellinger } ____cacheline_aligned;
322e48354ceSNicholas Bellinger
323e48354ceSNicholas Bellinger struct iscsi_ooo_cmdsn {
324e48354ceSNicholas Bellinger u16 cid;
325e48354ceSNicholas Bellinger u32 batch_count;
326e48354ceSNicholas Bellinger u32 cmdsn;
327e48354ceSNicholas Bellinger u32 exp_cmdsn;
32866cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd;
329e48354ceSNicholas Bellinger struct list_head ooo_list;
330e48354ceSNicholas Bellinger } ____cacheline_aligned;
331e48354ceSNicholas Bellinger
332e48354ceSNicholas Bellinger struct iscsi_datain {
333e48354ceSNicholas Bellinger u8 flags;
334e48354ceSNicholas Bellinger u32 data_sn;
335e48354ceSNicholas Bellinger u32 length;
336e48354ceSNicholas Bellinger u32 offset;
337e48354ceSNicholas Bellinger } ____cacheline_aligned;
338e48354ceSNicholas Bellinger
339e48354ceSNicholas Bellinger struct iscsi_r2t {
340e48354ceSNicholas Bellinger int seq_complete;
341e48354ceSNicholas Bellinger int recovery_r2t;
342e48354ceSNicholas Bellinger int sent_r2t;
343e48354ceSNicholas Bellinger u32 r2t_sn;
344e48354ceSNicholas Bellinger u32 offset;
345e48354ceSNicholas Bellinger u32 targ_xfer_tag;
346e48354ceSNicholas Bellinger u32 xfer_len;
347e48354ceSNicholas Bellinger struct list_head r2t_list;
348e48354ceSNicholas Bellinger } ____cacheline_aligned;
349e48354ceSNicholas Bellinger
35066cd9d4eSMax Gurtovoy struct iscsit_cmd {
351e48354ceSNicholas Bellinger enum iscsi_timer_flags_table dataout_timer_flags;
352e48354ceSNicholas Bellinger /* DataOUT timeout retries */
353e48354ceSNicholas Bellinger u8 dataout_timeout_retries;
354e48354ceSNicholas Bellinger /* Within command recovery count */
355e48354ceSNicholas Bellinger u8 error_recovery_count;
356e48354ceSNicholas Bellinger /* iSCSI dependent state for out or order CmdSNs */
357e48354ceSNicholas Bellinger enum cmd_i_state_table deferred_i_state;
358e48354ceSNicholas Bellinger /* iSCSI dependent state */
359e48354ceSNicholas Bellinger enum cmd_i_state_table i_state;
360e48354ceSNicholas Bellinger /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */
361e48354ceSNicholas Bellinger u8 immediate_cmd;
362e48354ceSNicholas Bellinger /* Immediate data present */
363e48354ceSNicholas Bellinger u8 immediate_data;
364e48354ceSNicholas Bellinger /* iSCSI Opcode */
365e48354ceSNicholas Bellinger u8 iscsi_opcode;
366e48354ceSNicholas Bellinger /* iSCSI Response Code */
367e48354ceSNicholas Bellinger u8 iscsi_response;
368e48354ceSNicholas Bellinger /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
369e48354ceSNicholas Bellinger u8 logout_reason;
370e48354ceSNicholas Bellinger /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */
371e48354ceSNicholas Bellinger u8 logout_response;
372e48354ceSNicholas Bellinger /* MaxCmdSN has been incremented */
373e48354ceSNicholas Bellinger u8 maxcmdsn_inc;
374e48354ceSNicholas Bellinger /* Immediate Unsolicited Dataout */
375e48354ceSNicholas Bellinger u8 unsolicited_data;
376ba159914SNicholas Bellinger /* Reject reason code */
377ba159914SNicholas Bellinger u8 reject_reason;
378e48354ceSNicholas Bellinger /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */
379e48354ceSNicholas Bellinger u16 logout_cid;
380e48354ceSNicholas Bellinger /* Command flags */
381e48354ceSNicholas Bellinger enum cmd_flags_table cmd_flags;
382e48354ceSNicholas Bellinger /* Initiator Task Tag assigned from Initiator */
38366c7db68SChristoph Hellwig itt_t init_task_tag;
384e48354ceSNicholas Bellinger /* Target Transfer Tag assigned from Target */
385e48354ceSNicholas Bellinger u32 targ_xfer_tag;
386e48354ceSNicholas Bellinger /* CmdSN assigned from Initiator */
387e48354ceSNicholas Bellinger u32 cmd_sn;
388e48354ceSNicholas Bellinger /* ExpStatSN assigned from Initiator */
389e48354ceSNicholas Bellinger u32 exp_stat_sn;
390e48354ceSNicholas Bellinger /* StatSN assigned to this ITT */
391e48354ceSNicholas Bellinger u32 stat_sn;
392e48354ceSNicholas Bellinger /* DataSN Counter */
393e48354ceSNicholas Bellinger u32 data_sn;
394e48354ceSNicholas Bellinger /* R2TSN Counter */
395e48354ceSNicholas Bellinger u32 r2t_sn;
396e48354ceSNicholas Bellinger /* Last DataSN acknowledged via DataAck SNACK */
397e48354ceSNicholas Bellinger u32 acked_data_sn;
398e48354ceSNicholas Bellinger /* Used for echoing NOPOUT ping data */
399e48354ceSNicholas Bellinger u32 buf_ptr_size;
400e48354ceSNicholas Bellinger /* Used to store DataDigest */
401e48354ceSNicholas Bellinger u32 data_crc;
402e48354ceSNicholas Bellinger /* Counter for MaxOutstandingR2T */
403e48354ceSNicholas Bellinger u32 outstanding_r2ts;
404e48354ceSNicholas Bellinger /* Next R2T Offset when DataSequenceInOrder=Yes */
405e48354ceSNicholas Bellinger u32 r2t_offset;
40666cd9d4eSMax Gurtovoy /* Iovec current and orig count for iscsit_cmd->iov_data */
407e48354ceSNicholas Bellinger u32 iov_data_count;
408e48354ceSNicholas Bellinger u32 orig_iov_data_count;
409e48354ceSNicholas Bellinger /* Number of miscellaneous iovecs used for IP stack calls */
410e48354ceSNicholas Bellinger u32 iov_misc_count;
41166cd9d4eSMax Gurtovoy /* Number of struct iscsi_pdu in struct iscsit_cmd->pdu_list */
412e48354ceSNicholas Bellinger u32 pdu_count;
41366cd9d4eSMax Gurtovoy /* Next struct iscsi_pdu to send in struct iscsit_cmd->pdu_list */
414e48354ceSNicholas Bellinger u32 pdu_send_order;
41566cd9d4eSMax Gurtovoy /* Current struct iscsi_pdu in struct iscsit_cmd->pdu_list */
416e48354ceSNicholas Bellinger u32 pdu_start;
41766cd9d4eSMax Gurtovoy /* Next struct iscsi_seq to send in struct iscsit_cmd->seq_list */
418e48354ceSNicholas Bellinger u32 seq_send_order;
41966cd9d4eSMax Gurtovoy /* Number of struct iscsi_seq in struct iscsit_cmd->seq_list */
420e48354ceSNicholas Bellinger u32 seq_count;
42166cd9d4eSMax Gurtovoy /* Current struct iscsi_seq in struct iscsit_cmd->seq_list */
422e48354ceSNicholas Bellinger u32 seq_no;
423e48354ceSNicholas Bellinger /* Lowest offset in current DataOUT sequence */
424e48354ceSNicholas Bellinger u32 seq_start_offset;
425e48354ceSNicholas Bellinger /* Highest offset in current DataOUT sequence */
426e48354ceSNicholas Bellinger u32 seq_end_offset;
427e48354ceSNicholas Bellinger /* Total size in bytes received so far of READ data */
428e48354ceSNicholas Bellinger u32 read_data_done;
429e48354ceSNicholas Bellinger /* Total size in bytes received so far of WRITE data */
430e48354ceSNicholas Bellinger u32 write_data_done;
431e48354ceSNicholas Bellinger /* Counter for FirstBurstLength key */
432e48354ceSNicholas Bellinger u32 first_burst_len;
433e48354ceSNicholas Bellinger /* Counter for MaxBurstLength key */
434e48354ceSNicholas Bellinger u32 next_burst_len;
435e48354ceSNicholas Bellinger /* Transfer size used for IP stack calls */
436e48354ceSNicholas Bellinger u32 tx_size;
437e48354ceSNicholas Bellinger /* Buffer used for various purposes */
438e48354ceSNicholas Bellinger void *buf_ptr;
4399864ca9dSNicholas Bellinger /* Used by SendTargets=[iqn.,eui.] discovery */
4409864ca9dSNicholas Bellinger void *text_in_ptr;
441e48354ceSNicholas Bellinger /* See include/linux/dma-mapping.h */
442e48354ceSNicholas Bellinger enum dma_data_direction data_direction;
443e48354ceSNicholas Bellinger /* iSCSI PDU Header + CRC */
444e48354ceSNicholas Bellinger unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN];
44566cd9d4eSMax Gurtovoy /* Number of times struct iscsit_cmd is present in immediate queue */
446e48354ceSNicholas Bellinger atomic_t immed_queue_count;
447e48354ceSNicholas Bellinger atomic_t response_queue_count;
448e48354ceSNicholas Bellinger spinlock_t datain_lock;
449e48354ceSNicholas Bellinger spinlock_t dataout_timeout_lock;
45066cd9d4eSMax Gurtovoy /* spinlock for protecting struct iscsit_cmd->i_state */
451e48354ceSNicholas Bellinger spinlock_t istate_lock;
452e48354ceSNicholas Bellinger /* spinlock for adding within command recovery entries */
453e48354ceSNicholas Bellinger spinlock_t error_lock;
454e48354ceSNicholas Bellinger /* spinlock for adding R2Ts */
455e48354ceSNicholas Bellinger spinlock_t r2t_lock;
456e48354ceSNicholas Bellinger /* DataIN List */
457e48354ceSNicholas Bellinger struct list_head datain_list;
458e48354ceSNicholas Bellinger /* R2T List */
459e48354ceSNicholas Bellinger struct list_head cmd_r2t_list;
460e48354ceSNicholas Bellinger /* Timer for DataOUT */
461e48354ceSNicholas Bellinger struct timer_list dataout_timer;
462e48354ceSNicholas Bellinger /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */
463e48354ceSNicholas Bellinger struct kvec *iov_data;
4640ca650c1SBart Van Assche void *overflow_buf;
465e48354ceSNicholas Bellinger /* Iovecs for miscellaneous purposes */
466e48354ceSNicholas Bellinger #define ISCSI_MISC_IOVECS 5
467e48354ceSNicholas Bellinger struct kvec iov_misc[ISCSI_MISC_IOVECS];
468e48354ceSNicholas Bellinger /* Array of struct iscsi_pdu used for DataPDUInOrder=No */
469e48354ceSNicholas Bellinger struct iscsi_pdu *pdu_list;
470e48354ceSNicholas Bellinger /* Current struct iscsi_pdu used for DataPDUInOrder=No */
471e48354ceSNicholas Bellinger struct iscsi_pdu *pdu_ptr;
472e48354ceSNicholas Bellinger /* Array of struct iscsi_seq used for DataSequenceInOrder=No */
473e48354ceSNicholas Bellinger struct iscsi_seq *seq_list;
474e48354ceSNicholas Bellinger /* Current struct iscsi_seq used for DataSequenceInOrder=No */
475e48354ceSNicholas Bellinger struct iscsi_seq *seq_ptr;
476e48354ceSNicholas Bellinger /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */
477e48354ceSNicholas Bellinger struct iscsi_tmr_req *tmr_req;
478e48354ceSNicholas Bellinger /* Connection this command is alligient to */
479be36d683SMax Gurtovoy struct iscsit_conn *conn;
480e48354ceSNicholas Bellinger /* Pointer to connection recovery entry */
481e48354ceSNicholas Bellinger struct iscsi_conn_recovery *cr;
482e48354ceSNicholas Bellinger /* Session the command is part of, used for connection recovery */
4830873fe44SMax Gurtovoy struct iscsit_session *sess;
484e48354ceSNicholas Bellinger /* list_head for connection list */
4852fbb471eSAndy Grover struct list_head i_conn_node;
486e48354ceSNicholas Bellinger /* The TCM I/O descriptor that is accessed via container_of() */
487e48354ceSNicholas Bellinger struct se_cmd se_cmd;
488e48354ceSNicholas Bellinger /* Sense buffer that will be mapped into outgoing status */
489e48354ceSNicholas Bellinger #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2)
490e48354ceSNicholas Bellinger unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN];
491e48354ceSNicholas Bellinger
492e48354ceSNicholas Bellinger u32 padding;
493e48354ceSNicholas Bellinger u8 pad_bytes[4];
494e48354ceSNicholas Bellinger
495e48354ceSNicholas Bellinger struct scatterlist *first_data_sg;
496e48354ceSNicholas Bellinger u32 first_data_sg_off;
497e48354ceSNicholas Bellinger u32 kmapped_nents;
498de103c93SChristoph Hellwig sense_reason_t sense_reason;
499e48354ceSNicholas Bellinger } ____cacheline_aligned;
500e48354ceSNicholas Bellinger
501e48354ceSNicholas Bellinger struct iscsi_tmr_req {
502e48354ceSNicholas Bellinger bool task_reassign:1;
503e48354ceSNicholas Bellinger u32 exp_data_sn;
50466cd9d4eSMax Gurtovoy struct iscsit_cmd *ref_cmd;
505e48354ceSNicholas Bellinger struct iscsi_conn_recovery *conn_recovery;
506e48354ceSNicholas Bellinger struct se_tmr_req *se_tmr_req;
507e48354ceSNicholas Bellinger };
508e48354ceSNicholas Bellinger
509be36d683SMax Gurtovoy struct iscsit_conn {
510d5627acbSRoland Dreier wait_queue_head_t queues_wq;
511e48354ceSNicholas Bellinger /* Authentication Successful for this connection */
512e48354ceSNicholas Bellinger u8 auth_complete;
513e48354ceSNicholas Bellinger /* State connection is currently in */
514e48354ceSNicholas Bellinger u8 conn_state;
515e48354ceSNicholas Bellinger u8 conn_logout_reason;
516e48354ceSNicholas Bellinger u8 network_transport;
517e48354ceSNicholas Bellinger enum iscsi_timer_flags_table nopin_timer_flags;
518e48354ceSNicholas Bellinger enum iscsi_timer_flags_table nopin_response_timer_flags;
519e48354ceSNicholas Bellinger /* Used to know what thread encountered a transport failure */
520e48354ceSNicholas Bellinger u8 which_thread;
521e48354ceSNicholas Bellinger /* connection id assigned by the Initiator */
522e48354ceSNicholas Bellinger u16 cid;
523e48354ceSNicholas Bellinger /* Remote TCP Port */
524e48354ceSNicholas Bellinger u16 login_port;
525e48354ceSNicholas Bellinger int net_size;
526baa4d64bSNicholas Bellinger int login_family;
527e48354ceSNicholas Bellinger u32 auth_id;
528e48354ceSNicholas Bellinger u32 conn_flags;
529e48354ceSNicholas Bellinger /* Used for iscsi_tx_login_rsp() */
53066c7db68SChristoph Hellwig itt_t login_itt;
531e48354ceSNicholas Bellinger u32 exp_statsn;
532e48354ceSNicholas Bellinger /* Per connection status sequence number */
533e48354ceSNicholas Bellinger u32 stat_sn;
53413a3cf08SAndy Grover struct sockaddr_storage login_sockaddr;
53513a3cf08SAndy Grover struct sockaddr_storage local_sockaddr;
536e48354ceSNicholas Bellinger int conn_usage_count;
537e48354ceSNicholas Bellinger int conn_waiting_on_uc;
538e48354ceSNicholas Bellinger atomic_t check_immediate_queue;
539e48354ceSNicholas Bellinger atomic_t conn_logout_remove;
540e48354ceSNicholas Bellinger atomic_t connection_exit;
541e48354ceSNicholas Bellinger atomic_t connection_recovery;
542e48354ceSNicholas Bellinger atomic_t connection_reinstatement;
543e48354ceSNicholas Bellinger atomic_t connection_wait_rcfr;
544e48354ceSNicholas Bellinger atomic_t sleep_on_conn_wait_comp;
545e48354ceSNicholas Bellinger atomic_t transport_failed;
546e48354ceSNicholas Bellinger struct completion conn_post_wait_comp;
547e48354ceSNicholas Bellinger struct completion conn_wait_comp;
548e48354ceSNicholas Bellinger struct completion conn_wait_rcfr_comp;
549e48354ceSNicholas Bellinger struct completion conn_waiting_on_uc_comp;
550e48354ceSNicholas Bellinger struct completion conn_logout_comp;
551e48354ceSNicholas Bellinger struct completion tx_half_close_comp;
552e48354ceSNicholas Bellinger struct completion rx_half_close_comp;
553e48354ceSNicholas Bellinger /* socket used by this connection */
554e48354ceSNicholas Bellinger struct socket *sock;
555676d2369SDavid S. Miller void (*orig_data_ready)(struct sock *);
556bb048357SNicholas Bellinger void (*orig_state_change)(struct sock *);
5574e108d4fSHou Pu #define LOGIN_FLAGS_READY 0
5584e108d4fSHou Pu #define LOGIN_FLAGS_INITIAL_PDU 1
5594e108d4fSHou Pu #define LOGIN_FLAGS_READ_ACTIVE 2
5604e108d4fSHou Pu #define LOGIN_FLAGS_WRITE_ACTIVE 3
5614e108d4fSHou Pu #define LOGIN_FLAGS_CLOSED 4
56213247018SMaurizio Lombardi #define LOGIN_FLAGS_WORKER_RUNNING 5
563a91eb7d9SNicholas Bellinger unsigned long login_flags;
564a91eb7d9SNicholas Bellinger struct delayed_work login_work;
565a91eb7d9SNicholas Bellinger struct iscsi_login *login;
566e48354ceSNicholas Bellinger struct timer_list nopin_timer;
567e48354ceSNicholas Bellinger struct timer_list nopin_response_timer;
56813247018SMaurizio Lombardi struct timer_list login_timer;
569d381a801SNicholas Bellinger struct task_struct *login_kworker;
570e48354ceSNicholas Bellinger /* Spinlock used for add/deleting cmd's from conn_cmd_list */
571e48354ceSNicholas Bellinger spinlock_t cmd_lock;
572e48354ceSNicholas Bellinger spinlock_t conn_usage_lock;
573e48354ceSNicholas Bellinger spinlock_t immed_queue_lock;
574e48354ceSNicholas Bellinger spinlock_t nopin_timer_lock;
575e48354ceSNicholas Bellinger spinlock_t response_queue_lock;
576e48354ceSNicholas Bellinger spinlock_t state_lock;
57713247018SMaurizio Lombardi spinlock_t login_timer_lock;
57813247018SMaurizio Lombardi spinlock_t login_worker_lock;
579e48354ceSNicholas Bellinger /* Used for scheduling TX and RX connection kthreads */
580e48354ceSNicholas Bellinger cpumask_var_t conn_cpumask;
581d72d827fSMingzhe Zou cpumask_var_t allowed_cpumask;
582f8d48ae5SDan Carpenter unsigned int conn_rx_reset_cpumask:1;
583f8d48ae5SDan Carpenter unsigned int conn_tx_reset_cpumask:1;
58466cd9d4eSMax Gurtovoy /* list_head of struct iscsit_cmd for this connection */
585e48354ceSNicholas Bellinger struct list_head conn_cmd_list;
586e48354ceSNicholas Bellinger struct list_head immed_queue_list;
587e48354ceSNicholas Bellinger struct list_head response_queue_list;
588e48354ceSNicholas Bellinger struct iscsi_conn_ops *conn_ops;
589baa4d64bSNicholas Bellinger struct iscsi_login *conn_login;
590baa4d64bSNicholas Bellinger struct iscsit_transport *conn_transport;
591e48354ceSNicholas Bellinger struct iscsi_param_list *param_list;
592e48354ceSNicholas Bellinger /* Used for per connection auth state machine */
593e48354ceSNicholas Bellinger void *auth_protocol;
594baa4d64bSNicholas Bellinger void *context;
595e48354ceSNicholas Bellinger struct iscsi_login_thread_s *login_thread;
596e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg;
597a91eb7d9SNicholas Bellinger struct iscsi_tpg_np *tpg_np;
598e48354ceSNicholas Bellinger /* Pointer to parent session */
5990873fe44SMax Gurtovoy struct iscsit_session *sess;
600becd9be6SMike Christie struct target_cmd_counter *cmd_cnt;
60188dcd2daSNicholas Bellinger int bitmap_id;
60288dcd2daSNicholas Bellinger int rx_thread_active;
60388dcd2daSNicholas Bellinger struct task_struct *rx_thread;
604e5419865SNicholas Bellinger struct completion rx_login_comp;
60588dcd2daSNicholas Bellinger int tx_thread_active;
60688dcd2daSNicholas Bellinger struct task_struct *tx_thread;
607e48354ceSNicholas Bellinger /* list_head for session connection list */
608e48354ceSNicholas Bellinger struct list_head conn_list;
609e48354ceSNicholas Bellinger } ____cacheline_aligned;
610e48354ceSNicholas Bellinger
611e48354ceSNicholas Bellinger struct iscsi_conn_recovery {
612e48354ceSNicholas Bellinger u16 cid;
613e48354ceSNicholas Bellinger u32 cmd_count;
614e48354ceSNicholas Bellinger u32 maxrecvdatasegmentlength;
6151c417f39SNicholas Bellinger u32 maxxmitdatasegmentlength;
616e48354ceSNicholas Bellinger int ready_for_reallegiance;
617e48354ceSNicholas Bellinger struct list_head conn_recovery_cmd_list;
618e48354ceSNicholas Bellinger spinlock_t conn_recovery_cmd_lock;
619e48354ceSNicholas Bellinger struct timer_list time2retain_timer;
6200873fe44SMax Gurtovoy struct iscsit_session *sess;
621e48354ceSNicholas Bellinger struct list_head cr_list;
622e48354ceSNicholas Bellinger } ____cacheline_aligned;
623e48354ceSNicholas Bellinger
6240873fe44SMax Gurtovoy struct iscsit_session {
625e48354ceSNicholas Bellinger u8 initiator_vendor;
626e48354ceSNicholas Bellinger u8 isid[6];
627e48354ceSNicholas Bellinger enum iscsi_timer_flags_table time2retain_timer_flags;
628e48354ceSNicholas Bellinger u8 version_active;
629e48354ceSNicholas Bellinger u16 cid_called;
630e48354ceSNicholas Bellinger u16 conn_recovery_count;
631e48354ceSNicholas Bellinger u16 tsih;
632e48354ceSNicholas Bellinger /* state session is currently in */
633e48354ceSNicholas Bellinger u32 session_state;
634e48354ceSNicholas Bellinger /* session wide counter: initiator assigned task tag */
63566c7db68SChristoph Hellwig itt_t init_task_tag;
636e48354ceSNicholas Bellinger /* session wide counter: target assigned task tag */
637e48354ceSNicholas Bellinger u32 targ_xfer_tag;
638e48354ceSNicholas Bellinger u32 cmdsn_window;
639e48354ceSNicholas Bellinger
640e48354ceSNicholas Bellinger /* protects cmdsn values */
641e48354ceSNicholas Bellinger struct mutex cmdsn_mutex;
642e48354ceSNicholas Bellinger /* session wide counter: expected command sequence number */
643e48354ceSNicholas Bellinger u32 exp_cmd_sn;
644e48354ceSNicholas Bellinger /* session wide counter: maximum allowed command sequence number */
645109e2381SRoland Dreier atomic_t max_cmd_sn;
646e48354ceSNicholas Bellinger struct list_head sess_ooo_cmdsn_list;
647e48354ceSNicholas Bellinger
648e48354ceSNicholas Bellinger /* LIO specific session ID */
649e48354ceSNicholas Bellinger u32 sid;
650e48354ceSNicholas Bellinger char auth_type[8];
651e48354ceSNicholas Bellinger /* unique within the target */
652e48354ceSNicholas Bellinger int session_index;
653e48354ceSNicholas Bellinger /* Used for session reference counting */
654e48354ceSNicholas Bellinger int session_usage_count;
655e48354ceSNicholas Bellinger int session_waiting_on_uc;
65604f3b31bSNicholas Bellinger atomic_long_t cmd_pdus;
65704f3b31bSNicholas Bellinger atomic_long_t rsp_pdus;
65804f3b31bSNicholas Bellinger atomic_long_t tx_data_octets;
65904f3b31bSNicholas Bellinger atomic_long_t rx_data_octets;
66004f3b31bSNicholas Bellinger atomic_long_t conn_digest_errors;
66104f3b31bSNicholas Bellinger atomic_long_t conn_timeout_errors;
662e48354ceSNicholas Bellinger u64 creation_time;
663e48354ceSNicholas Bellinger /* Number of active connections */
664e48354ceSNicholas Bellinger atomic_t nconn;
665e48354ceSNicholas Bellinger atomic_t session_continuation;
666e48354ceSNicholas Bellinger atomic_t session_fall_back_to_erl0;
667e48354ceSNicholas Bellinger atomic_t session_logout;
668e48354ceSNicholas Bellinger atomic_t session_reinstatement;
669e48354ceSNicholas Bellinger atomic_t session_stop_active;
67057c46e9fSMaurizio Lombardi atomic_t session_close;
671e48354ceSNicholas Bellinger /* connection list */
672e48354ceSNicholas Bellinger struct list_head sess_conn_list;
673e48354ceSNicholas Bellinger struct list_head cr_active_list;
674e48354ceSNicholas Bellinger struct list_head cr_inactive_list;
675e48354ceSNicholas Bellinger spinlock_t conn_lock;
676e48354ceSNicholas Bellinger spinlock_t cr_a_lock;
677e48354ceSNicholas Bellinger spinlock_t cr_i_lock;
678e48354ceSNicholas Bellinger spinlock_t session_usage_lock;
679e48354ceSNicholas Bellinger spinlock_t ttt_lock;
680e48354ceSNicholas Bellinger struct completion async_msg_comp;
681e48354ceSNicholas Bellinger struct completion reinstatement_comp;
682e48354ceSNicholas Bellinger struct completion session_wait_comp;
683e48354ceSNicholas Bellinger struct completion session_waiting_on_uc_comp;
684e48354ceSNicholas Bellinger struct timer_list time2retain_timer;
685e48354ceSNicholas Bellinger struct iscsi_sess_ops *sess_ops;
686e48354ceSNicholas Bellinger struct se_session *se_sess;
687e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg;
688e48354ceSNicholas Bellinger } ____cacheline_aligned;
689e48354ceSNicholas Bellinger
690e48354ceSNicholas Bellinger struct iscsi_login {
691e48354ceSNicholas Bellinger u8 auth_complete;
692e48354ceSNicholas Bellinger u8 checked_for_existing;
693e48354ceSNicholas Bellinger u8 current_stage;
694e48354ceSNicholas Bellinger u8 leading_connection;
695e48354ceSNicholas Bellinger u8 first_request;
696e48354ceSNicholas Bellinger u8 version_min;
697e48354ceSNicholas Bellinger u8 version_max;
698baa4d64bSNicholas Bellinger u8 login_complete;
699baa4d64bSNicholas Bellinger u8 login_failed;
700a91eb7d9SNicholas Bellinger bool zero_tsih;
701e48354ceSNicholas Bellinger char isid[6];
702e48354ceSNicholas Bellinger u32 cmd_sn;
70366c7db68SChristoph Hellwig itt_t init_task_tag;
704e48354ceSNicholas Bellinger u32 initial_exp_statsn;
705e48354ceSNicholas Bellinger u32 rsp_length;
706e48354ceSNicholas Bellinger u16 cid;
707e48354ceSNicholas Bellinger u16 tsih;
708baa4d64bSNicholas Bellinger char req[ISCSI_HDR_LEN];
709baa4d64bSNicholas Bellinger char rsp[ISCSI_HDR_LEN];
710e48354ceSNicholas Bellinger char *req_buf;
711e48354ceSNicholas Bellinger char *rsp_buf;
712be36d683SMax Gurtovoy struct iscsit_conn *conn;
713a91eb7d9SNicholas Bellinger struct iscsi_np *np;
714e48354ceSNicholas Bellinger } ____cacheline_aligned;
715e48354ceSNicholas Bellinger
716e48354ceSNicholas Bellinger struct iscsi_node_attrib {
717a6e0d179SDmitry Bogdanov s32 authentication;
718e48354ceSNicholas Bellinger u32 dataout_timeout;
719e48354ceSNicholas Bellinger u32 dataout_timeout_retries;
720e48354ceSNicholas Bellinger u32 default_erl;
721e48354ceSNicholas Bellinger u32 nopin_timeout;
722e48354ceSNicholas Bellinger u32 nopin_response_timeout;
723e48354ceSNicholas Bellinger u32 random_datain_pdu_offsets;
724e48354ceSNicholas Bellinger u32 random_datain_seq_offsets;
725e48354ceSNicholas Bellinger u32 random_r2t_offsets;
726e48354ceSNicholas Bellinger u32 tmr_cold_reset;
727e48354ceSNicholas Bellinger u32 tmr_warm_reset;
728e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl;
729e48354ceSNicholas Bellinger };
730e48354ceSNicholas Bellinger
731e48354ceSNicholas Bellinger struct se_dev_entry_s;
732e48354ceSNicholas Bellinger
733e48354ceSNicholas Bellinger struct iscsi_node_auth {
734e48354ceSNicholas Bellinger enum naf_flags_table naf_flags;
735e48354ceSNicholas Bellinger int authenticate_target;
736e48354ceSNicholas Bellinger /* Used for iscsit_global->discovery_auth,
737e48354ceSNicholas Bellinger * set to zero (auth disabled) by default */
738e48354ceSNicholas Bellinger int enforce_discovery_auth;
739e48354ceSNicholas Bellinger #define MAX_USER_LEN 256
740e48354ceSNicholas Bellinger #define MAX_PASS_LEN 256
741e48354ceSNicholas Bellinger char userid[MAX_USER_LEN];
742e48354ceSNicholas Bellinger char password[MAX_PASS_LEN];
743e48354ceSNicholas Bellinger char userid_mutual[MAX_USER_LEN];
744e48354ceSNicholas Bellinger char password_mutual[MAX_PASS_LEN];
745e48354ceSNicholas Bellinger };
746e48354ceSNicholas Bellinger
747e48354ceSNicholas Bellinger #include "iscsi_target_stat.h"
748e48354ceSNicholas Bellinger
749e48354ceSNicholas Bellinger struct iscsi_node_stat_grps {
750e48354ceSNicholas Bellinger struct config_group iscsi_sess_stats_group;
751e48354ceSNicholas Bellinger struct config_group iscsi_conn_stats_group;
752e48354ceSNicholas Bellinger };
753e48354ceSNicholas Bellinger
754e48354ceSNicholas Bellinger struct iscsi_node_acl {
755144bc4c2SChristoph Hellwig struct se_node_acl se_node_acl;
756e48354ceSNicholas Bellinger struct iscsi_node_attrib node_attrib;
757e48354ceSNicholas Bellinger struct iscsi_node_auth node_auth;
758e48354ceSNicholas Bellinger struct iscsi_node_stat_grps node_stat_grps;
759e48354ceSNicholas Bellinger };
760e48354ceSNicholas Bellinger
761a11b8069SDmitry Bogdanov static inline struct iscsi_node_acl *
to_iscsi_nacl(struct se_node_acl * se_nacl)762a11b8069SDmitry Bogdanov to_iscsi_nacl(struct se_node_acl *se_nacl)
763a11b8069SDmitry Bogdanov {
764a11b8069SDmitry Bogdanov return container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
765a11b8069SDmitry Bogdanov }
766a11b8069SDmitry Bogdanov
767e48354ceSNicholas Bellinger struct iscsi_tpg_attrib {
768e48354ceSNicholas Bellinger u32 authentication;
769e48354ceSNicholas Bellinger u32 login_timeout;
770e48354ceSNicholas Bellinger u32 generate_node_acls;
771e48354ceSNicholas Bellinger u32 cache_dynamic_acls;
772e48354ceSNicholas Bellinger u32 default_cmdsn_depth;
773e48354ceSNicholas Bellinger u32 demo_mode_write_protect;
774e48354ceSNicholas Bellinger u32 prod_mode_write_protect;
7754c54b6cfSThomas Glanzmann u32 demo_mode_discovery;
776d1fa7a1dSNicholas Bellinger u32 default_erl;
7775b168dcdSSagi Grimberg u8 t10_pi;
778901c04a3SNicholas Bellinger u32 fabric_prot_type;
779a6415cddSDavid Disseldorp u32 tpg_enabled_sendtargets;
780138d351eSNicholas Bellinger u32 login_keys_workaround;
781e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg;
782e48354ceSNicholas Bellinger };
783e48354ceSNicholas Bellinger
784e48354ceSNicholas Bellinger struct iscsi_np {
785e48354ceSNicholas Bellinger int np_network_transport;
786e48354ceSNicholas Bellinger int np_ip_proto;
787e48354ceSNicholas Bellinger int np_sock_type;
788e48354ceSNicholas Bellinger enum np_thread_state_table np_thread_state;
78914f4b54fSSagi Grimberg bool enabled;
790978d13d6SNicholas Bellinger atomic_t np_reset_count;
791e48354ceSNicholas Bellinger u32 np_exports;
792e48354ceSNicholas Bellinger enum np_flags_table np_flags;
793e48354ceSNicholas Bellinger spinlock_t np_thread_lock;
794e48354ceSNicholas Bellinger struct completion np_restart_comp;
795e48354ceSNicholas Bellinger struct socket *np_socket;
79613a3cf08SAndy Grover struct sockaddr_storage np_sockaddr;
797e48354ceSNicholas Bellinger struct task_struct *np_thread;
798baa4d64bSNicholas Bellinger void *np_context;
799baa4d64bSNicholas Bellinger struct iscsit_transport *np_transport;
800e48354ceSNicholas Bellinger struct list_head np_list;
801e48354ceSNicholas Bellinger } ____cacheline_aligned;
802e48354ceSNicholas Bellinger
803e48354ceSNicholas Bellinger struct iscsi_tpg_np {
804e48354ceSNicholas Bellinger struct iscsi_np *tpg_np;
805e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg;
806e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_parent;
807e48354ceSNicholas Bellinger struct list_head tpg_np_list;
808e48354ceSNicholas Bellinger struct list_head tpg_np_child_list;
809e48354ceSNicholas Bellinger struct list_head tpg_np_parent_list;
810e48354ceSNicholas Bellinger struct se_tpg_np se_tpg_np;
811e48354ceSNicholas Bellinger spinlock_t tpg_np_parent_lock;
812a91eb7d9SNicholas Bellinger struct completion tpg_np_comp;
813a91eb7d9SNicholas Bellinger struct kref tpg_np_kref;
814e48354ceSNicholas Bellinger };
815e48354ceSNicholas Bellinger
816e48354ceSNicholas Bellinger struct iscsi_portal_group {
817e48354ceSNicholas Bellinger unsigned char tpg_chap_id;
818e48354ceSNicholas Bellinger /* TPG State */
819e48354ceSNicholas Bellinger enum tpg_state_table tpg_state;
820e48354ceSNicholas Bellinger /* Target Portal Group Tag */
821e48354ceSNicholas Bellinger u16 tpgt;
822e48354ceSNicholas Bellinger /* Id assigned to target sessions */
823e48354ceSNicholas Bellinger u16 ntsih;
824e48354ceSNicholas Bellinger /* Number of active sessions */
825e48354ceSNicholas Bellinger u32 nsessions;
826e48354ceSNicholas Bellinger /* Number of Network Portals available for this TPG */
827e48354ceSNicholas Bellinger u32 num_tpg_nps;
828e48354ceSNicholas Bellinger /* Per TPG LIO specific session ID. */
829e48354ceSNicholas Bellinger u32 sid;
830e48354ceSNicholas Bellinger /* Spinlock for adding/removing Network Portals */
831e48354ceSNicholas Bellinger spinlock_t tpg_np_lock;
832e48354ceSNicholas Bellinger spinlock_t tpg_state_lock;
833e48354ceSNicholas Bellinger struct se_portal_group tpg_se_tpg;
834e48354ceSNicholas Bellinger struct mutex tpg_access_lock;
835a91eb7d9SNicholas Bellinger struct semaphore np_login_sem;
836e48354ceSNicholas Bellinger struct iscsi_tpg_attrib tpg_attrib;
837c3e51442SNicholas Bellinger struct iscsi_node_auth tpg_demo_auth;
838e48354ceSNicholas Bellinger /* Pointer to default list of iSCSI parameters for TPG */
839e48354ceSNicholas Bellinger struct iscsi_param_list *param_list;
840e48354ceSNicholas Bellinger struct iscsi_tiqn *tpg_tiqn;
841e48354ceSNicholas Bellinger struct list_head tpg_gnp_list;
842e48354ceSNicholas Bellinger struct list_head tpg_list;
843e48354ceSNicholas Bellinger } ____cacheline_aligned;
844e48354ceSNicholas Bellinger
845a11b8069SDmitry Bogdanov static inline struct iscsi_portal_group *
to_iscsi_tpg(struct se_portal_group * se_tpg)846a11b8069SDmitry Bogdanov to_iscsi_tpg(struct se_portal_group *se_tpg)
847a11b8069SDmitry Bogdanov {
848a11b8069SDmitry Bogdanov return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
849a11b8069SDmitry Bogdanov }
850a11b8069SDmitry Bogdanov
851e48354ceSNicholas Bellinger struct iscsi_wwn_stat_grps {
852e48354ceSNicholas Bellinger struct config_group iscsi_stat_group;
853e48354ceSNicholas Bellinger struct config_group iscsi_instance_group;
854e48354ceSNicholas Bellinger struct config_group iscsi_sess_err_group;
855e48354ceSNicholas Bellinger struct config_group iscsi_tgt_attr_group;
856e48354ceSNicholas Bellinger struct config_group iscsi_login_stats_group;
857e48354ceSNicholas Bellinger struct config_group iscsi_logout_stats_group;
858e48354ceSNicholas Bellinger };
859e48354ceSNicholas Bellinger
860e48354ceSNicholas Bellinger struct iscsi_tiqn {
861e48354ceSNicholas Bellinger unsigned char tiqn[ISCSI_IQN_LEN];
862e48354ceSNicholas Bellinger enum tiqn_state_table tiqn_state;
863e48354ceSNicholas Bellinger int tiqn_access_count;
864e48354ceSNicholas Bellinger u32 tiqn_active_tpgs;
865e48354ceSNicholas Bellinger u32 tiqn_ntpgs;
866e48354ceSNicholas Bellinger u32 tiqn_num_tpg_nps;
867e48354ceSNicholas Bellinger u32 tiqn_nsessions;
868e48354ceSNicholas Bellinger struct list_head tiqn_list;
869e48354ceSNicholas Bellinger struct list_head tiqn_tpg_list;
870e48354ceSNicholas Bellinger spinlock_t tiqn_state_lock;
871e48354ceSNicholas Bellinger spinlock_t tiqn_tpg_lock;
872e48354ceSNicholas Bellinger struct se_wwn tiqn_wwn;
873e48354ceSNicholas Bellinger struct iscsi_wwn_stat_grps tiqn_stat_grps;
874e48354ceSNicholas Bellinger int tiqn_index;
875e48354ceSNicholas Bellinger struct iscsi_sess_err_stats sess_err_stats;
876e48354ceSNicholas Bellinger struct iscsi_login_stats login_stats;
877e48354ceSNicholas Bellinger struct iscsi_logout_stats logout_stats;
878e48354ceSNicholas Bellinger } ____cacheline_aligned;
879e48354ceSNicholas Bellinger
880e48354ceSNicholas Bellinger struct iscsit_global {
881e48354ceSNicholas Bellinger /* In core shutdown */
882e48354ceSNicholas Bellinger u32 in_shutdown;
883e48354ceSNicholas Bellinger u32 active_ts;
884e48354ceSNicholas Bellinger /* Unique identifier used for the authentication daemon */
885e48354ceSNicholas Bellinger u32 auth_id;
886e48354ceSNicholas Bellinger u32 inactive_ts;
88788dcd2daSNicholas Bellinger #define ISCSIT_BITMAP_BITS 262144
888e48354ceSNicholas Bellinger /* Thread Set bitmap pointer */
889e48354ceSNicholas Bellinger unsigned long *ts_bitmap;
89088dcd2daSNicholas Bellinger spinlock_t ts_bitmap_lock;
891d72d827fSMingzhe Zou cpumask_var_t allowed_cpumask;
892e48354ceSNicholas Bellinger /* Used for iSCSI discovery session authentication */
893e48354ceSNicholas Bellinger struct iscsi_node_acl discovery_acl;
894e48354ceSNicholas Bellinger struct iscsi_portal_group *discovery_tpg;
895e48354ceSNicholas Bellinger };
896e48354ceSNicholas Bellinger
session_get_next_ttt(struct iscsit_session * session)8970873fe44SMax Gurtovoy static inline u32 session_get_next_ttt(struct iscsit_session *session)
898c1e34b64SSagi Grimberg {
899c1e34b64SSagi Grimberg u32 ttt;
900c1e34b64SSagi Grimberg
901c1e34b64SSagi Grimberg spin_lock_bh(&session->ttt_lock);
902c1e34b64SSagi Grimberg ttt = session->targ_xfer_tag++;
903c1e34b64SSagi Grimberg if (ttt == 0xFFFFFFFF)
904c1e34b64SSagi Grimberg ttt = session->targ_xfer_tag++;
905c1e34b64SSagi Grimberg spin_unlock_bh(&session->ttt_lock);
906c1e34b64SSagi Grimberg
907c1e34b64SSagi Grimberg return ttt;
908c1e34b64SSagi Grimberg }
909c1e34b64SSagi Grimberg
910be36d683SMax Gurtovoy extern struct iscsit_cmd *iscsit_find_cmd_from_itt(struct iscsit_conn *, itt_t);
911c0b7373bSVarun Prakash
912be36d683SMax Gurtovoy extern void iscsit_thread_check_cpumask(struct iscsit_conn *conn,
913c0b7373bSVarun Prakash struct task_struct *p,
914d72d827fSMingzhe Zou int mode);
915d72d827fSMingzhe Zou
916e48354ceSNicholas Bellinger #endif /* ISCSI_TARGET_CORE_H */
917