target: Fix incorrect starting offset after MODE_SENSE refactoring
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / target / target_core_base.h
CommitLineData
c66ac9db
NB
1#ifndef TARGET_CORE_BASE_H
2#define TARGET_CORE_BASE_H
3
4#include <linux/in.h>
5#include <linux/configfs.h>
6#include <linux/dma-mapping.h>
7#include <linux/blkdev.h>
8#include <scsi/scsi_cmnd.h>
9#include <net/sock.h>
10#include <net/tcp.h>
c66ac9db 11
9765b1f3 12#define TARGET_CORE_MOD_VERSION "v4.1.0-rc2-ml"
c4795fb2 13#define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
c66ac9db 14
c66ac9db 15/* Maximum Number of LUNs per Target Portal Group */
d0229ae3 16/* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
c66ac9db
NB
17#define TRANSPORT_MAX_LUNS_PER_TPG 256
18/*
19 * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
20 *
21 * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
22 * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
23 * 16-byte CDBs by default and require an extra allocation for
25985edc 24 * 32-byte CDBs to because of legacy issues.
c66ac9db
NB
25 *
26 * Within TCM Core there are no such legacy limitiations, so we go ahead
27 * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
28 * within all TCM Core and subsystem plugin code.
29 */
30#define TCM_MAX_COMMAND_SIZE 32
31/*
32 * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
33 * defined 96, but the real limit is 252 (or 260 including the header)
34 */
35#define TRANSPORT_SENSE_BUFFER SCSI_SENSE_BUFFERSIZE
36/* Used by transport_send_check_condition_and_sense() */
37#define SPC_SENSE_KEY_OFFSET 2
895f3022 38#define SPC_ADD_SENSE_LEN_OFFSET 7
c66ac9db
NB
39#define SPC_ASC_KEY_OFFSET 12
40#define SPC_ASCQ_KEY_OFFSET 13
41#define TRANSPORT_IQN_LEN 224
42/* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
43#define LU_GROUP_NAME_BUF 256
44/* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
45#define TG_PT_GROUP_NAME_BUF 256
46/* Used to parse VPD into struct t10_vpd */
47#define VPD_TMP_BUF_SIZE 128
48/* Used by transport_generic_cmd_sequencer() */
49#define READ_BLOCK_LEN 6
50#define READ_CAP_LEN 8
51#define READ_POSITION_LEN 20
52#define INQUIRY_LEN 36
53/* Used by transport_get_inquiry_vpd_serial() */
54#define INQUIRY_VPD_SERIAL_LEN 254
55/* Used by transport_get_inquiry_vpd_device_ident() */
56#define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254
57
c4795fb2
CH
58/* Attempts before moving from SHORT to LONG */
59#define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
60#define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
61#define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
62
63#define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
64
c4795fb2
CH
65/* struct se_dev_attrib sanity values */
66/* Default max_unmap_lba_count */
67#define DA_MAX_UNMAP_LBA_COUNT 0
68/* Default max_unmap_block_desc_count */
69#define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
70/* Default unmap_granularity */
71#define DA_UNMAP_GRANULARITY_DEFAULT 0
72/* Default unmap_granularity_alignment */
73#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
015487b8
RD
74/* Default max transfer length */
75#define DA_FABRIC_MAX_SECTORS 8192
c4795fb2
CH
76/* Emulation for Direct Page Out */
77#define DA_EMULATE_DPO 0
78/* Emulation for Forced Unit Access WRITEs */
79#define DA_EMULATE_FUA_WRITE 1
80/* Emulation for Forced Unit Access READs */
81#define DA_EMULATE_FUA_READ 0
82/* Emulation for WriteCache and SYNCHRONIZE_CACHE */
83#define DA_EMULATE_WRITE_CACHE 0
84/* Emulation for UNIT ATTENTION Interlock Control */
85#define DA_EMULATE_UA_INTLLCK_CTRL 0
86/* Emulation for TASK_ABORTED status (TAS) by default */
87#define DA_EMULATE_TAS 1
88/* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
89#define DA_EMULATE_TPU 0
90/*
91 * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
92 * block/blk-lib.c:blkdev_issue_discard()
93 */
94#define DA_EMULATE_TPWS 0
95/* No Emulation for PSCSI by default */
c4795fb2
CH
96#define DA_EMULATE_ALUA 0
97/* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
98#define DA_ENFORCE_PR_ISIDS 1
99#define DA_STATUS_MAX_SECTORS_MIN 16
100#define DA_STATUS_MAX_SECTORS_MAX 8192
101/* By default don't report non-rotating (solid state) medium */
102#define DA_IS_NONROT 0
103/* Queue Algorithm Modifier default for restricted reordering in control mode page */
104#define DA_EMULATE_REST_REORD 0
105
d95b8246 106#define SE_INQUIRY_BUF 512
c4795fb2 107#define SE_MODE_PAGE_BUF 512
32a8811f 108#define SE_SENSE_BUF 96
c4795fb2 109
c66ac9db
NB
110/* struct se_hba->hba_flags */
111enum hba_flags_table {
112 HBA_FLAGS_INTERNAL_USE = 0x01,
113 HBA_FLAGS_PSCSI_MODE = 0x02,
114};
115
116/* struct se_lun->lun_status */
117enum transport_lun_status_table {
118 TRANSPORT_LUN_STATUS_FREE = 0,
119 TRANSPORT_LUN_STATUS_ACTIVE = 1,
120};
121
122/* struct se_portal_group->se_tpg_type */
123enum transport_tpg_type_table {
124 TRANSPORT_TPG_TYPE_NORMAL = 0,
125 TRANSPORT_TPG_TYPE_DISCOVERY = 1,
126};
127
c66ac9db
NB
128/* Special transport agnostic struct se_cmd->t_states */
129enum transport_state_table {
130 TRANSPORT_NO_STATE = 0,
131 TRANSPORT_NEW_CMD = 1,
c66ac9db 132 TRANSPORT_WRITE_PENDING = 3,
c66ac9db 133 TRANSPORT_PROCESSING = 5,
35e0e757 134 TRANSPORT_COMPLETE = 6,
c66ac9db 135 TRANSPORT_ISTATE_PROCESSING = 11,
07bde79a 136 TRANSPORT_COMPLETE_QF_WP = 18,
e057f533 137 TRANSPORT_COMPLETE_QF_OK = 19,
c66ac9db
NB
138};
139
140/* Used for struct se_cmd->se_cmd_flags */
141enum se_cmd_flags_table {
142 SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
143 SCF_TRANSPORT_TASK_SENSE = 0x00000002,
144 SCF_EMULATED_TASK_SENSE = 0x00000004,
64f1db38
CH
145 SCF_SCSI_DATA_CDB = 0x00000008,
146 SCF_SCSI_TMR_CDB = 0x00000010,
147 SCF_SCSI_CDB_EXCEPTION = 0x00000020,
148 SCF_SCSI_RESERVATION_CONFLICT = 0x00000040,
149 SCF_FUA = 0x00000080,
150 SCF_SE_LUN_CMD = 0x00000100,
64f1db38
CH
151 SCF_BIDI = 0x00000400,
152 SCF_SENT_CHECK_CONDITION = 0x00000800,
153 SCF_OVERFLOW_BIT = 0x00001000,
154 SCF_UNDERFLOW_BIT = 0x00002000,
155 SCF_SENT_DELAYED_TAS = 0x00004000,
156 SCF_ALUA_NON_OPTIMIZED = 0x00008000,
64f1db38
CH
157 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
158 SCF_ACK_KREF = 0x00040000,
c66ac9db
NB
159};
160
161/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
162enum transport_lunflags_table {
163 TRANSPORT_LUNFLAGS_NO_ACCESS = 0x00,
164 TRANSPORT_LUNFLAGS_INITIATOR_ACCESS = 0x01,
165 TRANSPORT_LUNFLAGS_READ_ONLY = 0x02,
166 TRANSPORT_LUNFLAGS_READ_WRITE = 0x04,
167};
168
c66ac9db
NB
169/*
170 * Used by transport_send_check_condition_and_sense() and se_cmd->scsi_sense_reason
171 * to signal which ASC/ASCQ sense payload should be built.
172 */
173enum tcm_sense_reason_table {
174 TCM_NON_EXISTENT_LUN = 0x01,
175 TCM_UNSUPPORTED_SCSI_OPCODE = 0x02,
176 TCM_INCORRECT_AMOUNT_OF_DATA = 0x03,
177 TCM_UNEXPECTED_UNSOLICITED_DATA = 0x04,
178 TCM_SERVICE_CRC_ERROR = 0x05,
179 TCM_SNACK_REJECTED = 0x06,
180 TCM_SECTOR_COUNT_TOO_MANY = 0x07,
181 TCM_INVALID_CDB_FIELD = 0x08,
182 TCM_INVALID_PARAMETER_LIST = 0x09,
183 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = 0x0a,
184 TCM_UNKNOWN_MODE_PAGE = 0x0b,
185 TCM_WRITE_PROTECTED = 0x0c,
186 TCM_CHECK_CONDITION_ABORT_CMD = 0x0d,
187 TCM_CHECK_CONDITION_UNIT_ATTENTION = 0x0e,
188 TCM_CHECK_CONDITION_NOT_READY = 0x0f,
03e98c9e 189 TCM_RESERVATION_CONFLICT = 0x10,
e2397c70 190 TCM_ADDRESS_OUT_OF_RANGE = 0x11,
c66ac9db
NB
191};
192
a6360785
NB
193enum target_sc_flags_table {
194 TARGET_SCF_BIDI_OP = 0x01,
195 TARGET_SCF_ACK_KREF = 0x02,
b0d79946 196 TARGET_SCF_UNKNOWN_SIZE = 0x04,
a6360785
NB
197};
198
c4795fb2
CH
199/* fabric independent task management function values */
200enum tcm_tmreq_table {
201 TMR_ABORT_TASK = 1,
202 TMR_ABORT_TASK_SET = 2,
203 TMR_CLEAR_ACA = 3,
204 TMR_CLEAR_TASK_SET = 4,
205 TMR_LUN_RESET = 5,
206 TMR_TARGET_WARM_RESET = 6,
207 TMR_TARGET_COLD_RESET = 7,
208 TMR_FABRIC_TMR = 255,
209};
210
211/* fabric independent task management response values */
212enum tcm_tmrsp_table {
213 TMR_FUNCTION_COMPLETE = 0,
214 TMR_TASK_DOES_NOT_EXIST = 1,
215 TMR_LUN_DOES_NOT_EXIST = 2,
216 TMR_TASK_STILL_ALLEGIANT = 3,
217 TMR_TASK_FAILOVER_NOT_SUPPORTED = 4,
218 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 5,
219 TMR_FUNCTION_AUTHORIZATION_FAILED = 6,
220 TMR_FUNCTION_REJECTED = 255,
221};
222
e89d15ee
NB
223/*
224 * Used for target SCSI statistics
225 */
226typedef enum {
227 SCSI_INST_INDEX,
228 SCSI_DEVICE_INDEX,
229 SCSI_AUTH_INTR_INDEX,
230 SCSI_INDEX_TYPE_MAX
231} scsi_index_t;
232
c66ac9db
NB
233struct se_cmd;
234
235struct t10_alua {
c66ac9db
NB
236 /* ALUA Target Port Group ID */
237 u16 alua_tg_pt_gps_counter;
238 u32 alua_tg_pt_gps_count;
239 spinlock_t tg_pt_gps_lock;
0fd97ccf 240 struct se_device *t10_dev;
c66ac9db
NB
241 /* Used for default ALUA Target Port Group */
242 struct t10_alua_tg_pt_gp *default_tg_pt_gp;
243 /* Used for default ALUA Target Port Group ConfigFS group */
244 struct config_group alua_tg_pt_gps_group;
c66ac9db 245 struct list_head tg_pt_gps_list;
e0a53e70 246};
c66ac9db
NB
247
248struct t10_alua_lu_gp {
249 u16 lu_gp_id;
250 int lu_gp_valid_id;
251 u32 lu_gp_members;
c66ac9db
NB
252 atomic_t lu_gp_ref_cnt;
253 spinlock_t lu_gp_lock;
254 struct config_group lu_gp_group;
e3d6f909 255 struct list_head lu_gp_node;
c66ac9db 256 struct list_head lu_gp_mem_list;
e0a53e70 257};
c66ac9db
NB
258
259struct t10_alua_lu_gp_member {
5dd7ed2e 260 bool lu_gp_assoc;
c66ac9db
NB
261 atomic_t lu_gp_mem_ref_cnt;
262 spinlock_t lu_gp_mem_lock;
263 struct t10_alua_lu_gp *lu_gp;
264 struct se_device *lu_gp_mem_dev;
265 struct list_head lu_gp_mem_list;
e0a53e70 266};
c66ac9db
NB
267
268struct t10_alua_tg_pt_gp {
269 u16 tg_pt_gp_id;
270 int tg_pt_gp_valid_id;
271 int tg_pt_gp_alua_access_status;
272 int tg_pt_gp_alua_access_type;
273 int tg_pt_gp_nonop_delay_msecs;
274 int tg_pt_gp_trans_delay_msecs;
5b9a4d72 275 int tg_pt_gp_implict_trans_secs;
c66ac9db
NB
276 int tg_pt_gp_pref;
277 int tg_pt_gp_write_metadata;
278 /* Used by struct t10_alua_tg_pt_gp->tg_pt_gp_md_buf_len */
279#define ALUA_MD_BUF_LEN 1024
280 u32 tg_pt_gp_md_buf_len;
281 u32 tg_pt_gp_members;
282 atomic_t tg_pt_gp_alua_access_state;
283 atomic_t tg_pt_gp_ref_cnt;
284 spinlock_t tg_pt_gp_lock;
285 struct mutex tg_pt_gp_md_mutex;
0fd97ccf 286 struct se_device *tg_pt_gp_dev;
c66ac9db
NB
287 struct config_group tg_pt_gp_group;
288 struct list_head tg_pt_gp_list;
289 struct list_head tg_pt_gp_mem_list;
e0a53e70 290};
c66ac9db
NB
291
292struct t10_alua_tg_pt_gp_member {
5dd7ed2e 293 bool tg_pt_gp_assoc;
c66ac9db
NB
294 atomic_t tg_pt_gp_mem_ref_cnt;
295 spinlock_t tg_pt_gp_mem_lock;
296 struct t10_alua_tg_pt_gp *tg_pt_gp;
297 struct se_port *tg_pt;
298 struct list_head tg_pt_gp_mem_list;
e0a53e70 299};
c66ac9db
NB
300
301struct t10_vpd {
302 unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
303 int protocol_identifier_set;
304 u32 protocol_identifier;
305 u32 device_identifier_code_set;
306 u32 association;
307 u32 device_identifier_type;
308 struct list_head vpd_list;
e0a53e70 309};
c66ac9db
NB
310
311struct t10_wwn {
e3d6f909
AG
312 char vendor[8];
313 char model[16];
314 char revision[4];
315 char unit_serial[INQUIRY_VPD_SERIAL_LEN];
c66ac9db 316 spinlock_t t10_vpd_lock;
0fd97ccf 317 struct se_device *t10_dev;
c66ac9db
NB
318 struct config_group t10_wwn_group;
319 struct list_head t10_vpd_list;
e0a53e70 320};
c66ac9db 321
c66ac9db
NB
322struct t10_pr_registration {
323 /* Used for fabrics that contain WWN+ISID */
324#define PR_REG_ISID_LEN 16
325 /* PR_REG_ISID_LEN + ',i,0x' */
326#define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
327 char pr_reg_isid[PR_REG_ISID_LEN];
328 /* Used during APTPL metadata reading */
329#define PR_APTPL_MAX_IPORT_LEN 256
330 unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
331 /* Used during APTPL metadata reading */
332#define PR_APTPL_MAX_TPORT_LEN 256
333 unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
334 /* For writing out live meta data */
335 unsigned char *pr_aptpl_buf;
336 u16 pr_aptpl_rpti;
337 u16 pr_reg_tpgt;
338 /* Reservation effects all target ports */
339 int pr_reg_all_tg_pt;
340 /* Activate Persistence across Target Power Loss */
341 int pr_reg_aptpl;
342 int pr_res_holder;
343 int pr_res_type;
344 int pr_res_scope;
345 /* Used for fabric initiator WWPNs using a ISID */
5dd7ed2e 346 bool isid_present_at_reg;
c66ac9db
NB
347 u32 pr_res_mapped_lun;
348 u32 pr_aptpl_target_lun;
349 u32 pr_res_generation;
350 u64 pr_reg_bin_isid;
351 u64 pr_res_key;
352 atomic_t pr_res_holders;
353 struct se_node_acl *pr_reg_nacl;
354 struct se_dev_entry *pr_reg_deve;
355 struct se_lun *pr_reg_tg_pt_lun;
356 struct list_head pr_reg_list;
357 struct list_head pr_reg_abort_list;
358 struct list_head pr_reg_aptpl_list;
359 struct list_head pr_reg_atp_list;
360 struct list_head pr_reg_atp_mem_list;
e0a53e70 361};
c66ac9db 362
e3d6f909 363struct t10_reservation {
c66ac9db
NB
364 /* Reservation effects all target ports */
365 int pr_all_tg_pt;
366 /* Activate Persistence across Target Power Loss enabled
367 * for SCSI device */
368 int pr_aptpl_active;
e3d6f909 369 /* Used by struct t10_reservation->pr_aptpl_buf_len */
c66ac9db
NB
370#define PR_APTPL_BUF_LEN 8192
371 u32 pr_aptpl_buf_len;
372 u32 pr_generation;
c66ac9db
NB
373 spinlock_t registration_lock;
374 spinlock_t aptpl_reg_lock;
375 /*
376 * This will always be set by one individual I_T Nexus.
377 * However with all_tg_pt=1, other I_T Nexus from the
378 * same initiator can access PR reg/res info on a different
379 * target port.
380 *
381 * There is also the 'All Registrants' case, where there is
382 * a single *pr_res_holder of the reservation, but all
383 * registrations are considered reservation holders.
384 */
385 struct se_node_acl *pr_res_holder;
386 struct list_head registration_list;
387 struct list_head aptpl_reg_list;
e0a53e70 388};
c66ac9db 389
c8e31f26
AG
390struct se_tmr_req {
391 /* Task Management function to be performed */
392 u8 function;
393 /* Task Management response to send */
394 u8 response;
395 int call_transport;
396 /* Reference to ITT that Task Mgmt should be performed */
397 u32 ref_task_tag;
c8e31f26
AG
398 void *fabric_tmr_ptr;
399 struct se_cmd *task_cmd;
c8e31f26
AG
400 struct se_device *tmr_dev;
401 struct se_lun *tmr_lun;
402 struct list_head tmr_list;
403};
404
c66ac9db
NB
405struct se_cmd {
406 /* SAM response code being sent to initiator */
407 u8 scsi_status;
408 u8 scsi_asc;
409 u8 scsi_ascq;
410 u8 scsi_sense_reason;
411 u16 scsi_sense_length;
412 /* Delay for ALUA Active/NonOptimized state access in milliseconds */
413 int alua_nonop_delay;
414 /* See include/linux/dma-mapping.h */
415 enum dma_data_direction data_direction;
416 /* For SAM Task Attribute */
417 int sam_task_attr;
418 /* Transport protocol dependent state, see transport_state_table */
419 enum transport_state_table t_state;
a17f091d 420 /* Used to signal cmd->se_tfo->check_release_cmd() usage per cmd */
5f655e8d
BVA
421 unsigned check_release:1;
422 unsigned cmd_wait_set:1;
b0d79946 423 unsigned unknown_data_length:1;
c66ac9db
NB
424 /* See se_cmd_flags_table */
425 u32 se_cmd_flags;
426 u32 se_ordered_id;
427 /* Total size in bytes associated with command */
428 u32 data_length;
c66ac9db
NB
429 u32 residual_count;
430 u32 orig_fe_lun;
431 /* Persistent Reservation key */
432 u64 pr_res_key;
c66ac9db
NB
433 /* Used for sense data */
434 void *sense_buffer;
5951146d 435 struct list_head se_delayed_node;
5951146d 436 struct list_head se_lun_node;
07bde79a 437 struct list_head se_qf_node;
c66ac9db
NB
438 struct se_device *se_dev;
439 struct se_dev_entry *se_deve;
c66ac9db
NB
440 struct se_lun *se_lun;
441 /* Only used for internal passthrough and legacy TCM fabric modules */
442 struct se_session *se_sess;
443 struct se_tmr_req *se_tmr_req;
a17f091d
NB
444 struct list_head se_cmd_list;
445 struct completion cmd_wait_comp;
7481deb4 446 struct kref cmd_kref;
c66ac9db 447 struct target_core_fabric_ops *se_tfo;
6bb35e00 448 int (*execute_cmd)(struct se_cmd *);
c66ac9db 449 void (*transport_complete_callback)(struct se_cmd *);
07bde79a 450
a1d8b49a
AG
451 unsigned char *t_task_cdb;
452 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
453 unsigned long long t_task_lba;
a1d8b49a 454 atomic_t t_fe_count;
7d680f3b
CH
455 unsigned int transport_state;
456#define CMD_T_ABORTED (1 << 0)
457#define CMD_T_ACTIVE (1 << 1)
458#define CMD_T_COMPLETE (1 << 2)
459#define CMD_T_QUEUED (1 << 3)
460#define CMD_T_SENT (1 << 4)
461#define CMD_T_STOP (1 << 5)
462#define CMD_T_FAILED (1 << 6)
463#define CMD_T_LUN_STOP (1 << 7)
464#define CMD_T_LUN_FE_STOP (1 << 8)
465#define CMD_T_DEV_ACTIVE (1 << 9)
cf572a96
CH
466#define CMD_T_REQUEST_STOP (1 << 10)
467#define CMD_T_BUSY (1 << 11)
a1d8b49a
AG
468 spinlock_t t_state_lock;
469 struct completion t_transport_stop_comp;
470 struct completion transport_lun_fe_stop_comp;
471 struct completion transport_lun_stop_comp;
05d1c7c0 472
35e0e757
CH
473 struct work_struct work;
474
ec98f782
AG
475 struct scatterlist *t_data_sg;
476 unsigned int t_data_nents;
4949314c 477 void *t_data_vmap;
ec98f782
AG
478 struct scatterlist *t_bidi_data_sg;
479 unsigned int t_bidi_data_nents;
480
cf572a96
CH
481 struct list_head state_list;
482 bool state_active;
483
484 /* old task stop completion, consider merging with some of the above */
485 struct completion task_stop_comp;
486
5787cacd
CH
487 /* backend private data */
488 void *priv;
e0a53e70 489};
c66ac9db 490
c66ac9db
NB
491struct se_ua {
492 u8 ua_asc;
493 u8 ua_ascq;
494 struct se_node_acl *ua_nacl;
495 struct list_head ua_dev_list;
496 struct list_head ua_nacl_list;
e0a53e70 497};
c66ac9db
NB
498
499struct se_node_acl {
500 char initiatorname[TRANSPORT_IQN_LEN];
501 /* Used to signal demo mode created ACL, disabled by default */
5dd7ed2e 502 bool dynamic_node_acl;
337c0607 503 bool acl_stop:1;
c66ac9db
NB
504 u32 queue_depth;
505 u32 acl_index;
506 u64 num_cmds;
507 u64 read_bytes;
508 u64 write_bytes;
509 spinlock_t stats_lock;
510 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
511 atomic_t acl_pr_ref_count;
f2083241 512 struct se_dev_entry **device_list;
c66ac9db
NB
513 struct se_session *nacl_sess;
514 struct se_portal_group *se_tpg;
515 spinlock_t device_list_lock;
516 spinlock_t nacl_sess_lock;
517 struct config_group acl_group;
518 struct config_group acl_attrib_group;
519 struct config_group acl_auth_group;
520 struct config_group acl_param_group;
12d23384
NB
521 struct config_group acl_fabric_stat_group;
522 struct config_group *acl_default_groups[5];
c66ac9db
NB
523 struct list_head acl_list;
524 struct list_head acl_sess_list;
01468346 525 struct completion acl_free_comp;
afb999ff 526 struct kref acl_kref;
e0a53e70 527};
c66ac9db
NB
528
529struct se_session {
5f655e8d 530 unsigned sess_tearing_down:1;
c66ac9db
NB
531 u64 sess_bin_isid;
532 struct se_node_acl *se_node_acl;
533 struct se_portal_group *se_tpg;
534 void *fabric_sess_ptr;
535 struct list_head sess_list;
536 struct list_head sess_acl_list;
a17f091d 537 struct list_head sess_cmd_list;
a17f091d 538 spinlock_t sess_cmd_lock;
41ac82b6 539 struct kref sess_kref;
e0a53e70 540};
c66ac9db 541
c66ac9db
NB
542struct se_device;
543struct se_transform_info;
544struct scatterlist;
545
12d23384
NB
546struct se_ml_stat_grps {
547 struct config_group stat_group;
548 struct config_group scsi_auth_intr_group;
549 struct config_group scsi_att_intr_port_group;
550};
551
c66ac9db
NB
552struct se_lun_acl {
553 char initiatorname[TRANSPORT_IQN_LEN];
554 u32 mapped_lun;
555 struct se_node_acl *se_lun_nacl;
556 struct se_lun *se_lun;
557 struct list_head lacl_list;
558 struct config_group se_lun_group;
12d23384 559 struct se_ml_stat_grps ml_stat_grps;
e0a53e70 560};
c66ac9db
NB
561
562struct se_dev_entry {
5dd7ed2e 563 bool def_pr_registered;
c66ac9db
NB
564 /* See transport_lunflags_table */
565 u32 lun_flags;
566 u32 deve_cmds;
567 u32 mapped_lun;
568 u32 average_bytes;
569 u32 last_byte_count;
570 u32 total_cmds;
571 u32 total_bytes;
572 u64 pr_res_key;
573 u64 creation_time;
574 u32 attach_count;
575 u64 read_bytes;
576 u64 write_bytes;
577 atomic_t ua_count;
578 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
579 atomic_t pr_ref_count;
580 struct se_lun_acl *se_lun_acl;
581 spinlock_t ua_lock;
582 struct se_lun *se_lun;
583 struct list_head alua_port_list;
584 struct list_head ua_list;
e0a53e70 585};
c66ac9db 586
c66ac9db
NB
587struct se_dev_attrib {
588 int emulate_dpo;
589 int emulate_fua_write;
590 int emulate_fua_read;
591 int emulate_write_cache;
592 int emulate_ua_intlck_ctrl;
593 int emulate_tas;
594 int emulate_tpu;
595 int emulate_tpws;
c66ac9db 596 int enforce_pr_isids;
e22a7f07 597 int is_nonrot;
5de619a3 598 int emulate_rest_reord;
c66ac9db
NB
599 u32 hw_block_size;
600 u32 block_size;
601 u32 hw_max_sectors;
015487b8 602 u32 fabric_max_sectors;
c66ac9db
NB
603 u32 optimal_sectors;
604 u32 hw_queue_depth;
605 u32 queue_depth;
c66ac9db
NB
606 u32 max_unmap_lba_count;
607 u32 max_unmap_block_desc_count;
608 u32 unmap_granularity;
609 u32 unmap_granularity_alignment;
0fd97ccf 610 struct se_device *da_dev;
c66ac9db 611 struct config_group da_group;
e0a53e70 612};
c66ac9db 613
12d23384
NB
614struct se_dev_stat_grps {
615 struct config_group stat_group;
616 struct config_group scsi_dev_group;
617 struct config_group scsi_tgt_dev_group;
618 struct config_group scsi_lu_group;
619};
620
c66ac9db 621struct se_device {
c66ac9db
NB
622 /* RELATIVE TARGET PORT IDENTIFER Counter */
623 u16 dev_rpti_counter;
624 /* Used for SAM Task Attribute ordering */
625 u32 dev_cur_ordered_id;
626 u32 dev_flags;
0fd97ccf
CH
627#define DF_CONFIGURED 0x00000001
628#define DF_FIRMWARE_VPD_UNIT_SERIAL 0x00000002
629#define DF_EMULATED_VPD_UNIT_SERIAL 0x00000004
630#define DF_USING_UDEV_PATH 0x00000008
631#define DF_USING_ALIAS 0x00000010
c66ac9db 632 u32 dev_port_count;
c66ac9db
NB
633 /* Physical device queue depth */
634 u32 queue_depth;
635 /* Used for SPC-2 reservations enforce of ISIDs */
636 u64 dev_res_bin_isid;
c66ac9db 637 /* Pointer to transport specific device structure */
c66ac9db
NB
638 u32 dev_index;
639 u64 creation_time;
640 u32 num_resets;
641 u64 num_cmds;
642 u64 read_bytes;
643 u64 write_bytes;
644 spinlock_t stats_lock;
645 /* Active commands on this virtual SE device */
c66ac9db 646 atomic_t simple_cmds;
c66ac9db 647 atomic_t dev_ordered_id;
c66ac9db 648 atomic_t dev_ordered_sync;
07bde79a 649 atomic_t dev_qf_count;
0fd97ccf 650 int export_count;
c66ac9db 651 spinlock_t delayed_cmd_lock;
c66ac9db 652 spinlock_t execute_task_lock;
c66ac9db 653 spinlock_t dev_reservation_lock;
0fd97ccf
CH
654 unsigned int dev_reservation_flags;
655#define DRF_SPC2_RESERVATIONS 0x00000001
656#define DRF_SPC2_RESERVATIONS_WITH_ISID 0x00000002
c66ac9db
NB
657 spinlock_t se_port_lock;
658 spinlock_t se_tmr_lock;
07bde79a 659 spinlock_t qf_cmd_lock;
c66ac9db
NB
660 /* Used for legacy SPC-2 reservationsa */
661 struct se_node_acl *dev_reserved_node_acl;
662 /* Used for ALUA Logical Unit Group membership */
663 struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
664 /* Used for SPC-3 Persistent Reservations */
665 struct t10_pr_registration *dev_pr_res_holder;
666 struct list_head dev_sep_list;
667 struct list_head dev_tmr_list;
af877292 668 struct workqueue_struct *tmr_wq;
07bde79a 669 struct work_struct qf_work_queue;
c66ac9db 670 struct list_head delayed_cmd_list;
cf572a96 671 struct list_head state_list;
07bde79a 672 struct list_head qf_cmd_list;
c66ac9db
NB
673 /* Pointer to associated SE HBA */
674 struct se_hba *se_hba;
0fd97ccf
CH
675 /* T10 Inquiry and VPD WWN Information */
676 struct t10_wwn t10_wwn;
677 /* T10 Asymmetric Logical Unit Assignment for Target Ports */
678 struct t10_alua t10_alua;
679 /* T10 SPC-2 + SPC-3 Reservations */
680 struct t10_reservation t10_pr;
681 struct se_dev_attrib dev_attrib;
682 struct config_group dev_group;
683 struct config_group dev_pr_group;
684 struct se_dev_stat_grps dev_stat_grps;
685#define SE_DEV_ALIAS_LEN 512 /* must be less than PAGE_SIZE */
686 unsigned char dev_alias[SE_DEV_ALIAS_LEN];
687#define SE_UDEV_PATH_LEN 512 /* must be less than PAGE_SIZE */
688 unsigned char udev_path[SE_UDEV_PATH_LEN];
c66ac9db
NB
689 /* Pointer to template of function pointers for transport */
690 struct se_subsystem_api *transport;
691 /* Linked list for struct se_hba struct se_device list */
692 struct list_head dev_list;
e0a53e70 693};
c66ac9db 694
c66ac9db
NB
695struct se_hba {
696 u16 hba_tpgt;
697 u32 hba_id;
698 /* See hba_flags_table */
699 u32 hba_flags;
700 /* Virtual iSCSI devices attached. */
701 u32 dev_count;
702 u32 hba_index;
c66ac9db
NB
703 /* Pointer to transport specific host structure. */
704 void *hba_ptr;
e3d6f909 705 struct list_head hba_node;
c66ac9db 706 spinlock_t device_lock;
c66ac9db
NB
707 struct config_group hba_group;
708 struct mutex hba_access_mutex;
709 struct se_subsystem_api *transport;
e0a53e70 710};
c66ac9db 711
12d23384
NB
712struct se_port_stat_grps {
713 struct config_group stat_group;
714 struct config_group scsi_port_group;
715 struct config_group scsi_tgt_port_group;
716 struct config_group scsi_transport_group;
717};
718
c66ac9db
NB
719struct se_lun {
720 /* See transport_lun_status_table */
721 enum transport_lun_status_table lun_status;
722 u32 lun_access;
723 u32 lun_flags;
724 u32 unpacked_lun;
725 atomic_t lun_acl_count;
726 spinlock_t lun_acl_lock;
727 spinlock_t lun_cmd_lock;
728 spinlock_t lun_sep_lock;
729 struct completion lun_shutdown_comp;
730 struct list_head lun_cmd_list;
731 struct list_head lun_acl_list;
732 struct se_device *lun_se_dev;
12d23384 733 struct se_port *lun_sep;
c66ac9db 734 struct config_group lun_group;
12d23384 735 struct se_port_stat_grps port_stat_grps;
e0a53e70 736};
c66ac9db 737
e89d15ee
NB
738struct scsi_port_stats {
739 u64 cmd_pdus;
740 u64 tx_data_octets;
741 u64 rx_data_octets;
e0a53e70 742};
e89d15ee 743
c66ac9db
NB
744struct se_port {
745 /* RELATIVE TARGET PORT IDENTIFER */
746 u16 sep_rtpi;
747 int sep_tg_pt_secondary_stat;
748 int sep_tg_pt_secondary_write_md;
749 u32 sep_index;
750 struct scsi_port_stats sep_stats;
751 /* Used for ALUA Target Port Groups membership */
c66ac9db
NB
752 atomic_t sep_tg_pt_secondary_offline;
753 /* Used for PR ALL_TG_PT=1 */
754 atomic_t sep_tg_pt_ref_cnt;
755 spinlock_t sep_alua_lock;
756 struct mutex sep_tg_pt_md_mutex;
757 struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem;
758 struct se_lun *sep_lun;
759 struct se_portal_group *sep_tpg;
760 struct list_head sep_alua_list;
761 struct list_head sep_list;
e0a53e70 762};
c66ac9db
NB
763
764struct se_tpg_np {
1f6fe7cb 765 struct se_portal_group *tpg_np_parent;
c66ac9db 766 struct config_group tpg_np_group;
e0a53e70 767};
c66ac9db
NB
768
769struct se_portal_group {
770 /* Type of target portal group, see transport_tpg_type_table */
771 enum transport_tpg_type_table se_tpg_type;
772 /* Number of ACLed Initiator Nodes for this TPG */
773 u32 num_node_acls;
774 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
775 atomic_t tpg_pr_ref_count;
776 /* Spinlock for adding/removing ACLed Nodes */
777 spinlock_t acl_node_lock;
778 /* Spinlock for adding/removing sessions */
779 spinlock_t session_lock;
780 spinlock_t tpg_lun_lock;
781 /* Pointer to $FABRIC_MOD portal group */
782 void *se_tpg_fabric_ptr;
e3d6f909 783 struct list_head se_tpg_node;
c66ac9db
NB
784 /* linked list for initiator ACL list */
785 struct list_head acl_node_list;
4a5a75f3 786 struct se_lun **tpg_lun_list;
c66ac9db 787 struct se_lun tpg_virt_lun0;
25985edc 788 /* List of TCM sessions associated wth this TPG */
c66ac9db
NB
789 struct list_head tpg_sess_list;
790 /* Pointer to $FABRIC_MOD dependent code */
791 struct target_core_fabric_ops *se_tpg_tfo;
792 struct se_wwn *se_tpg_wwn;
793 struct config_group tpg_group;
794 struct config_group *tpg_default_groups[6];
795 struct config_group tpg_lun_group;
796 struct config_group tpg_np_group;
797 struct config_group tpg_acl_group;
798 struct config_group tpg_attrib_group;
799 struct config_group tpg_param_group;
e0a53e70 800};
c66ac9db 801
c66ac9db
NB
802struct se_wwn {
803 struct target_fabric_configfs *wwn_tf;
804 struct config_group wwn_group;
12d23384
NB
805 struct config_group *wwn_default_groups[2];
806 struct config_group fabric_stat_group;
e0a53e70 807};
c66ac9db 808
c66ac9db 809#endif /* TARGET_CORE_BASE_H */