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