]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/target/target_core_base.h
target/user: Fix inconsistent kmap_atomic/kunmap_atomic
[mirror_ubuntu-bionic-kernel.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>
c0add7fd 8#include <linux/percpu_ida.h>
c66ac9db
NB
9#include <scsi/scsi_cmnd.h>
10#include <net/sock.h>
11#include <net/tcp.h>
c66ac9db 12
2999ee7f 13#define TARGET_CORE_MOD_VERSION "v4.1.0"
c4795fb2 14#define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
c66ac9db 15
c66ac9db
NB
16/*
17 * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
18 *
19 * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
20 * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
21 * 16-byte CDBs by default and require an extra allocation for
25985edc 22 * 32-byte CDBs to because of legacy issues.
c66ac9db
NB
23 *
24 * Within TCM Core there are no such legacy limitiations, so we go ahead
25 * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
26 * within all TCM Core and subsystem plugin code.
27 */
28#define TCM_MAX_COMMAND_SIZE 32
29/*
30 * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
31 * defined 96, but the real limit is 252 (or 260 including the header)
32 */
33#define TRANSPORT_SENSE_BUFFER SCSI_SENSE_BUFFERSIZE
34/* Used by transport_send_check_condition_and_sense() */
35#define SPC_SENSE_KEY_OFFSET 2
895f3022 36#define SPC_ADD_SENSE_LEN_OFFSET 7
76736db3
SG
37#define SPC_DESC_TYPE_OFFSET 8
38#define SPC_ADDITIONAL_DESC_LEN_OFFSET 9
39#define SPC_VALIDITY_OFFSET 10
c66ac9db
NB
40#define SPC_ASC_KEY_OFFSET 12
41#define SPC_ASCQ_KEY_OFFSET 13
42#define TRANSPORT_IQN_LEN 224
43/* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
44#define LU_GROUP_NAME_BUF 256
45/* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
46#define TG_PT_GROUP_NAME_BUF 256
47/* Used to parse VPD into struct t10_vpd */
703d641d 48#define VPD_TMP_BUF_SIZE 254
c66ac9db
NB
49/* Used by transport_generic_cmd_sequencer() */
50#define READ_BLOCK_LEN 6
51#define READ_CAP_LEN 8
52#define READ_POSITION_LEN 20
53#define INQUIRY_LEN 36
54/* Used by transport_get_inquiry_vpd_serial() */
55#define INQUIRY_VPD_SERIAL_LEN 254
56/* Used by transport_get_inquiry_vpd_device_ident() */
57#define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254
58
c4795fb2
CH
59/* Attempts before moving from SHORT to LONG */
60#define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
61#define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
62#define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
63
64#define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
65
c4795fb2
CH
66/* struct se_dev_attrib sanity values */
67/* Default max_unmap_lba_count */
68#define DA_MAX_UNMAP_LBA_COUNT 0
69/* Default max_unmap_block_desc_count */
70#define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
71/* Default unmap_granularity */
72#define DA_UNMAP_GRANULARITY_DEFAULT 0
73/* Default unmap_granularity_alignment */
74#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
773cbaf7
NB
75/* Default max_write_same_len, disabled by default */
76#define DA_MAX_WRITE_SAME_LEN 0
adfa9570
TB
77/* Use a model alias based on the configfs backend device name */
78#define DA_EMULATE_MODEL_ALIAS 0
c4795fb2
CH
79/* Emulation for WriteCache and SYNCHRONIZE_CACHE */
80#define DA_EMULATE_WRITE_CACHE 0
81/* Emulation for UNIT ATTENTION Interlock Control */
82#define DA_EMULATE_UA_INTLLCK_CTRL 0
83/* Emulation for TASK_ABORTED status (TAS) by default */
84#define DA_EMULATE_TAS 1
85/* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
86#define DA_EMULATE_TPU 0
87/*
88 * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
89 * block/blk-lib.c:blkdev_issue_discard()
90 */
91#define DA_EMULATE_TPWS 0
0123a9ec
NB
92/* Emulation for CompareAndWrite (AtomicTestandSet) by default */
93#define DA_EMULATE_CAW 1
d397a445
NB
94/* Emulation for 3rd Party Copy (ExtendedCopy) by default */
95#define DA_EMULATE_3PC 1
c4795fb2 96/* No Emulation for PSCSI by default */
c4795fb2
CH
97#define DA_EMULATE_ALUA 0
98/* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
99#define DA_ENFORCE_PR_ISIDS 1
92404e60
NB
100/* Force SPC-3 PR Activate Persistence across Target Power Loss */
101#define DA_FORCE_PR_APTPL 0
c4795fb2
CH
102#define DA_STATUS_MAX_SECTORS_MIN 16
103#define DA_STATUS_MAX_SECTORS_MAX 8192
104/* By default don't report non-rotating (solid state) medium */
105#define DA_IS_NONROT 0
106/* Queue Algorithm Modifier default for restricted reordering in control mode page */
107#define DA_EMULATE_REST_REORD 0
108
f82f320e 109#define SE_INQUIRY_BUF 1024
c4795fb2 110#define SE_MODE_PAGE_BUF 512
32a8811f 111#define SE_SENSE_BUF 96
c4795fb2 112
c66ac9db
NB
113/* struct se_hba->hba_flags */
114enum hba_flags_table {
115 HBA_FLAGS_INTERNAL_USE = 0x01,
116 HBA_FLAGS_PSCSI_MODE = 0x02,
117};
118
c66ac9db
NB
119/* Special transport agnostic struct se_cmd->t_states */
120enum transport_state_table {
121 TRANSPORT_NO_STATE = 0,
122 TRANSPORT_NEW_CMD = 1,
c66ac9db 123 TRANSPORT_WRITE_PENDING = 3,
c66ac9db 124 TRANSPORT_PROCESSING = 5,
35e0e757 125 TRANSPORT_COMPLETE = 6,
c66ac9db 126 TRANSPORT_ISTATE_PROCESSING = 11,
07bde79a 127 TRANSPORT_COMPLETE_QF_WP = 18,
e057f533 128 TRANSPORT_COMPLETE_QF_OK = 19,
c66ac9db
NB
129};
130
131/* Used for struct se_cmd->se_cmd_flags */
132enum se_cmd_flags_table {
133 SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
134 SCF_TRANSPORT_TASK_SENSE = 0x00000002,
135 SCF_EMULATED_TASK_SENSE = 0x00000004,
64f1db38
CH
136 SCF_SCSI_DATA_CDB = 0x00000008,
137 SCF_SCSI_TMR_CDB = 0x00000010,
64f1db38
CH
138 SCF_FUA = 0x00000080,
139 SCF_SE_LUN_CMD = 0x00000100,
64f1db38
CH
140 SCF_BIDI = 0x00000400,
141 SCF_SENT_CHECK_CONDITION = 0x00000800,
142 SCF_OVERFLOW_BIT = 0x00001000,
143 SCF_UNDERFLOW_BIT = 0x00002000,
68259b5a 144 SCF_SEND_DELAYED_TAS = 0x00004000,
64f1db38 145 SCF_ALUA_NON_OPTIMIZED = 0x00008000,
64f1db38 146 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
a82a9538
NB
147 SCF_COMPARE_AND_WRITE = 0x00080000,
148 SCF_COMPARE_AND_WRITE_POST = 0x00100000,
5835812f 149 SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC = 0x00200000,
c66ac9db
NB
150};
151
152/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
153enum transport_lunflags_table {
29a05dee
NB
154 TRANSPORT_LUNFLAGS_READ_ONLY = 0x01,
155 TRANSPORT_LUNFLAGS_READ_WRITE = 0x02,
c66ac9db
NB
156};
157
c66ac9db 158/*
de103c93 159 * Used by transport_send_check_condition_and_sense()
c66ac9db
NB
160 * to signal which ASC/ASCQ sense payload should be built.
161 */
de103c93
CH
162typedef unsigned __bitwise__ sense_reason_t;
163
c66ac9db 164enum tcm_sense_reason_table {
de103c93 165#define R(x) (__force sense_reason_t )(x)
ba829137 166 TCM_NO_SENSE = R(0x00),
de103c93
CH
167 TCM_NON_EXISTENT_LUN = R(0x01),
168 TCM_UNSUPPORTED_SCSI_OPCODE = R(0x02),
169 TCM_INCORRECT_AMOUNT_OF_DATA = R(0x03),
170 TCM_UNEXPECTED_UNSOLICITED_DATA = R(0x04),
171 TCM_SERVICE_CRC_ERROR = R(0x05),
172 TCM_SNACK_REJECTED = R(0x06),
173 TCM_SECTOR_COUNT_TOO_MANY = R(0x07),
174 TCM_INVALID_CDB_FIELD = R(0x08),
175 TCM_INVALID_PARAMETER_LIST = R(0x09),
176 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = R(0x0a),
177 TCM_UNKNOWN_MODE_PAGE = R(0x0b),
178 TCM_WRITE_PROTECTED = R(0x0c),
179 TCM_CHECK_CONDITION_ABORT_CMD = R(0x0d),
180 TCM_CHECK_CONDITION_UNIT_ATTENTION = R(0x0e),
181 TCM_CHECK_CONDITION_NOT_READY = R(0x0f),
182 TCM_RESERVATION_CONFLICT = R(0x10),
183 TCM_ADDRESS_OUT_OF_RANGE = R(0x11),
184 TCM_OUT_OF_RESOURCES = R(0x12),
bb992e72 185 TCM_PARAMETER_LIST_LENGTH_ERROR = R(0x13),
818b571c 186 TCM_MISCOMPARE_VERIFY = R(0x14),
fcc4f17b
NB
187 TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED = R(0x15),
188 TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = R(0x16),
189 TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = R(0x17),
de103c93 190#undef R
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,
c4795fb2
CH
208};
209
210/* fabric independent task management response values */
211enum tcm_tmrsp_table {
a314d700 212 TMR_FUNCTION_FAILED = 0,
11fee8a7
JE
213 TMR_FUNCTION_COMPLETE = 1,
214 TMR_TASK_DOES_NOT_EXIST = 2,
215 TMR_LUN_DOES_NOT_EXIST = 3,
216 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 4,
217 TMR_FUNCTION_REJECTED = 5,
c4795fb2
CH
218};
219
e89d15ee
NB
220/*
221 * Used for target SCSI statistics
222 */
223typedef enum {
224 SCSI_INST_INDEX,
225 SCSI_DEVICE_INDEX,
226 SCSI_AUTH_INTR_INDEX,
227 SCSI_INDEX_TYPE_MAX
228} scsi_index_t;
229
c66ac9db
NB
230struct se_cmd;
231
c66094bf
HR
232struct t10_alua_lba_map_member {
233 struct list_head lba_map_mem_list;
234 int lba_map_mem_alua_state;
235 int lba_map_mem_alua_pg_id;
236};
237
238struct t10_alua_lba_map {
239 u64 lba_map_first_lba;
240 u64 lba_map_last_lba;
241 struct list_head lba_map_list;
242 struct list_head lba_map_mem_list;
243};
244
c66ac9db 245struct t10_alua {
c66ac9db
NB
246 /* ALUA Target Port Group ID */
247 u16 alua_tg_pt_gps_counter;
248 u32 alua_tg_pt_gps_count;
c66094bf
HR
249 /* Referrals support */
250 spinlock_t lba_map_lock;
251 u32 lba_map_segment_size;
252 u32 lba_map_segment_multiplier;
253 struct list_head lba_map_list;
c66ac9db 254 spinlock_t tg_pt_gps_lock;
0fd97ccf 255 struct se_device *t10_dev;
c66ac9db
NB
256 /* Used for default ALUA Target Port Group */
257 struct t10_alua_tg_pt_gp *default_tg_pt_gp;
258 /* Used for default ALUA Target Port Group ConfigFS group */
259 struct config_group alua_tg_pt_gps_group;
c66ac9db 260 struct list_head tg_pt_gps_list;
e0a53e70 261};
c66ac9db
NB
262
263struct t10_alua_lu_gp {
264 u16 lu_gp_id;
265 int lu_gp_valid_id;
266 u32 lu_gp_members;
c66ac9db
NB
267 atomic_t lu_gp_ref_cnt;
268 spinlock_t lu_gp_lock;
269 struct config_group lu_gp_group;
e3d6f909 270 struct list_head lu_gp_node;
c66ac9db 271 struct list_head lu_gp_mem_list;
e0a53e70 272};
c66ac9db
NB
273
274struct t10_alua_lu_gp_member {
5dd7ed2e 275 bool lu_gp_assoc;
c66ac9db
NB
276 atomic_t lu_gp_mem_ref_cnt;
277 spinlock_t lu_gp_mem_lock;
278 struct t10_alua_lu_gp *lu_gp;
279 struct se_device *lu_gp_mem_dev;
280 struct list_head lu_gp_mem_list;
e0a53e70 281};
c66ac9db
NB
282
283struct t10_alua_tg_pt_gp {
284 u16 tg_pt_gp_id;
285 int tg_pt_gp_valid_id;
c0dc941e 286 int tg_pt_gp_alua_supported_states;
dfbce75a
HR
287 int tg_pt_gp_alua_pending_state;
288 int tg_pt_gp_alua_previous_state;
c66ac9db
NB
289 int tg_pt_gp_alua_access_status;
290 int tg_pt_gp_alua_access_type;
291 int tg_pt_gp_nonop_delay_msecs;
292 int tg_pt_gp_trans_delay_msecs;
125d0119 293 int tg_pt_gp_implicit_trans_secs;
c66ac9db
NB
294 int tg_pt_gp_pref;
295 int tg_pt_gp_write_metadata;
c66ac9db
NB
296 u32 tg_pt_gp_members;
297 atomic_t tg_pt_gp_alua_access_state;
298 atomic_t tg_pt_gp_ref_cnt;
299 spinlock_t tg_pt_gp_lock;
300 struct mutex tg_pt_gp_md_mutex;
0fd97ccf 301 struct se_device *tg_pt_gp_dev;
c66ac9db
NB
302 struct config_group tg_pt_gp_group;
303 struct list_head tg_pt_gp_list;
adf653f9
CH
304 struct list_head tg_pt_gp_lun_list;
305 struct se_lun *tg_pt_gp_alua_lun;
9c6e164c
HR
306 struct se_node_acl *tg_pt_gp_alua_nacl;
307 struct delayed_work tg_pt_gp_transition_work;
308 struct completion *tg_pt_gp_transition_complete;
e0a53e70 309};
c66ac9db 310
c66ac9db
NB
311struct t10_vpd {
312 unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
313 int protocol_identifier_set;
314 u32 protocol_identifier;
315 u32 device_identifier_code_set;
316 u32 association;
317 u32 device_identifier_type;
318 struct list_head vpd_list;
e0a53e70 319};
c66ac9db
NB
320
321struct t10_wwn {
e3d6f909
AG
322 char vendor[8];
323 char model[16];
324 char revision[4];
325 char unit_serial[INQUIRY_VPD_SERIAL_LEN];
c66ac9db 326 spinlock_t t10_vpd_lock;
0fd97ccf 327 struct se_device *t10_dev;
c66ac9db
NB
328 struct config_group t10_wwn_group;
329 struct list_head t10_vpd_list;
e0a53e70 330};
c66ac9db 331
c66ac9db
NB
332struct t10_pr_registration {
333 /* Used for fabrics that contain WWN+ISID */
334#define PR_REG_ISID_LEN 16
335 /* PR_REG_ISID_LEN + ',i,0x' */
336#define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
337 char pr_reg_isid[PR_REG_ISID_LEN];
338 /* Used during APTPL metadata reading */
339#define PR_APTPL_MAX_IPORT_LEN 256
340 unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
341 /* Used during APTPL metadata reading */
342#define PR_APTPL_MAX_TPORT_LEN 256
343 unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
c66ac9db
NB
344 u16 pr_aptpl_rpti;
345 u16 pr_reg_tpgt;
346 /* Reservation effects all target ports */
347 int pr_reg_all_tg_pt;
348 /* Activate Persistence across Target Power Loss */
349 int pr_reg_aptpl;
350 int pr_res_holder;
351 int pr_res_type;
352 int pr_res_scope;
353 /* Used for fabric initiator WWPNs using a ISID */
5dd7ed2e 354 bool isid_present_at_reg;
f2d30680
HR
355 u64 pr_res_mapped_lun;
356 u64 pr_aptpl_target_lun;
79dc9c9e 357 u16 tg_pt_sep_rtpi;
c66ac9db
NB
358 u32 pr_res_generation;
359 u64 pr_reg_bin_isid;
360 u64 pr_res_key;
361 atomic_t pr_res_holders;
362 struct se_node_acl *pr_reg_nacl;
79dc9c9e 363 /* Used by ALL_TG_PT=1 registration with deve->pr_ref taken */
c66ac9db 364 struct se_dev_entry *pr_reg_deve;
c66ac9db
NB
365 struct list_head pr_reg_list;
366 struct list_head pr_reg_abort_list;
367 struct list_head pr_reg_aptpl_list;
368 struct list_head pr_reg_atp_list;
369 struct list_head pr_reg_atp_mem_list;
e0a53e70 370};
c66ac9db 371
e3d6f909 372struct t10_reservation {
c66ac9db
NB
373 /* Reservation effects all target ports */
374 int pr_all_tg_pt;
375 /* Activate Persistence across Target Power Loss enabled
376 * for SCSI device */
377 int pr_aptpl_active;
f161d4b4 378#define PR_APTPL_BUF_LEN 262144
c66ac9db 379 u32 pr_generation;
c66ac9db
NB
380 spinlock_t registration_lock;
381 spinlock_t aptpl_reg_lock;
382 /*
383 * This will always be set by one individual I_T Nexus.
384 * However with all_tg_pt=1, other I_T Nexus from the
385 * same initiator can access PR reg/res info on a different
386 * target port.
387 *
388 * There is also the 'All Registrants' case, where there is
389 * a single *pr_res_holder of the reservation, but all
390 * registrations are considered reservation holders.
391 */
392 struct se_node_acl *pr_res_holder;
393 struct list_head registration_list;
394 struct list_head aptpl_reg_list;
e0a53e70 395};
c66ac9db 396
c8e31f26
AG
397struct se_tmr_req {
398 /* Task Management function to be performed */
399 u8 function;
400 /* Task Management response to send */
401 u8 response;
402 int call_transport;
403 /* Reference to ITT that Task Mgmt should be performed */
649ee054 404 u64 ref_task_tag;
c8e31f26
AG
405 void *fabric_tmr_ptr;
406 struct se_cmd *task_cmd;
c8e31f26
AG
407 struct se_device *tmr_dev;
408 struct se_lun *tmr_lun;
409 struct list_head tmr_list;
410};
411
ce65e5b9 412enum target_prot_op {
e70beee7
NB
413 TARGET_PROT_NORMAL = 0,
414 TARGET_PROT_DIN_INSERT = (1 << 0),
415 TARGET_PROT_DOUT_INSERT = (1 << 1),
416 TARGET_PROT_DIN_STRIP = (1 << 2),
417 TARGET_PROT_DOUT_STRIP = (1 << 3),
418 TARGET_PROT_DIN_PASS = (1 << 4),
419 TARGET_PROT_DOUT_PASS = (1 << 5),
ce65e5b9
NB
420};
421
e70beee7
NB
422#define TARGET_PROT_ALL TARGET_PROT_DIN_INSERT | TARGET_PROT_DOUT_INSERT | \
423 TARGET_PROT_DIN_STRIP | TARGET_PROT_DOUT_STRIP | \
424 TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS
425
ce65e5b9
NB
426enum target_prot_type {
427 TARGET_DIF_TYPE0_PROT,
428 TARGET_DIF_TYPE1_PROT,
429 TARGET_DIF_TYPE2_PROT,
430 TARGET_DIF_TYPE3_PROT,
431};
432
19f9361a
SG
433enum target_core_dif_check {
434 TARGET_DIF_CHECK_GUARD = 0x1 << 0,
435 TARGET_DIF_CHECK_APPTAG = 0x1 << 1,
436 TARGET_DIF_CHECK_REFTAG = 0x1 << 2,
437};
438
ce65e5b9
NB
439struct se_dif_v1_tuple {
440 __be16 guard_tag;
441 __be16 app_tag;
442 __be32 ref_tag;
443};
444
68d81f40
CH
445/* for sam_task_attr */
446#define TCM_SIMPLE_TAG 0x20
447#define TCM_HEAD_TAG 0x21
448#define TCM_ORDERED_TAG 0x22
449#define TCM_ACA_TAG 0x24
450
c66ac9db
NB
451struct se_cmd {
452 /* SAM response code being sent to initiator */
453 u8 scsi_status;
454 u8 scsi_asc;
455 u8 scsi_ascq;
c66ac9db 456 u16 scsi_sense_length;
649ee054 457 u64 tag; /* SAM command identifier aka task tag */
c66ac9db
NB
458 /* Delay for ALUA Active/NonOptimized state access in milliseconds */
459 int alua_nonop_delay;
460 /* See include/linux/dma-mapping.h */
461 enum dma_data_direction data_direction;
462 /* For SAM Task Attribute */
463 int sam_task_attr;
c0add7fd
NB
464 /* Used for se_sess->sess_tag_pool */
465 unsigned int map_tag;
c66ac9db
NB
466 /* Transport protocol dependent state, see transport_state_table */
467 enum transport_state_table t_state;
5f655e8d 468 unsigned cmd_wait_set:1;
b0d79946 469 unsigned unknown_data_length:1;
c66ac9db
NB
470 /* See se_cmd_flags_table */
471 u32 se_cmd_flags;
472 u32 se_ordered_id;
473 /* Total size in bytes associated with command */
474 u32 data_length;
c66ac9db 475 u32 residual_count;
f2d30680 476 u64 orig_fe_lun;
c66ac9db
NB
477 /* Persistent Reservation key */
478 u64 pr_res_key;
c66ac9db
NB
479 /* Used for sense data */
480 void *sense_buffer;
5951146d 481 struct list_head se_delayed_node;
07bde79a 482 struct list_head se_qf_node;
c66ac9db 483 struct se_device *se_dev;
c66ac9db
NB
484 struct se_lun *se_lun;
485 /* Only used for internal passthrough and legacy TCM fabric modules */
486 struct se_session *se_sess;
487 struct se_tmr_req *se_tmr_req;
a17f091d
NB
488 struct list_head se_cmd_list;
489 struct completion cmd_wait_comp;
7481deb4 490 struct kref cmd_kref;
9ac8928e 491 const struct target_core_fabric_ops *se_tfo;
de103c93 492 sense_reason_t (*execute_cmd)(struct se_cmd *);
a82a9538
NB
493 sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *,
494 u32, enum dma_data_direction);
c8e63985 495 sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool);
07bde79a 496
a1d8b49a
AG
497 unsigned char *t_task_cdb;
498 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
499 unsigned long long t_task_lba;
a82a9538 500 unsigned int t_task_nolb;
7d680f3b
CH
501 unsigned int transport_state;
502#define CMD_T_ABORTED (1 << 0)
503#define CMD_T_ACTIVE (1 << 1)
504#define CMD_T_COMPLETE (1 << 2)
7d680f3b
CH
505#define CMD_T_SENT (1 << 4)
506#define CMD_T_STOP (1 << 5)
4a9a6c8d
NB
507#define CMD_T_DEV_ACTIVE (1 << 7)
508#define CMD_T_REQUEST_STOP (1 << 8)
509#define CMD_T_BUSY (1 << 9)
a1d8b49a
AG
510 spinlock_t t_state_lock;
511 struct completion t_transport_stop_comp;
05d1c7c0 512
35e0e757
CH
513 struct work_struct work;
514
ec98f782 515 struct scatterlist *t_data_sg;
47e459e6 516 struct scatterlist *t_data_sg_orig;
ec98f782 517 unsigned int t_data_nents;
47e459e6 518 unsigned int t_data_nents_orig;
4949314c 519 void *t_data_vmap;
ec98f782
AG
520 struct scatterlist *t_bidi_data_sg;
521 unsigned int t_bidi_data_nents;
522
cf572a96
CH
523 struct list_head state_list;
524 bool state_active;
525
526 /* old task stop completion, consider merging with some of the above */
527 struct completion task_stop_comp;
528
5787cacd
CH
529 /* backend private data */
530 void *priv;
5277797d
NB
531
532 /* Used for lun->lun_ref counting */
5259a06e 533 int lun_ref_active;
ce65e5b9
NB
534
535 /* DIF related members */
536 enum target_prot_op prot_op;
537 enum target_prot_type prot_type;
19f9361a 538 u8 prot_checks;
ce65e5b9
NB
539 u32 prot_length;
540 u32 reftag_seed;
541 struct scatterlist *t_prot_sg;
542 unsigned int t_prot_nents;
ce65e5b9 543 sense_reason_t pi_err;
76736db3 544 sector_t bad_sector;
b5b8e298 545 bool prot_pto;
e0a53e70 546};
c66ac9db 547
c66ac9db
NB
548struct se_ua {
549 u8 ua_asc;
550 u8 ua_ascq;
c66ac9db 551 struct list_head ua_nacl_list;
e0a53e70 552};
c66ac9db
NB
553
554struct se_node_acl {
555 char initiatorname[TRANSPORT_IQN_LEN];
556 /* Used to signal demo mode created ACL, disabled by default */
5dd7ed2e 557 bool dynamic_node_acl;
337c0607 558 bool acl_stop:1;
c66ac9db
NB
559 u32 queue_depth;
560 u32 acl_index;
bffb5128 561 enum target_prot_type saved_prot_type;
79e62fc3
AG
562#define MAX_ACL_TAG_SIZE 64
563 char acl_tag[MAX_ACL_TAG_SIZE];
c66ac9db
NB
564 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
565 atomic_t acl_pr_ref_count;
29a05dee 566 struct hlist_head lun_entry_hlist;
c66ac9db
NB
567 struct se_session *nacl_sess;
568 struct se_portal_group *se_tpg;
29a05dee 569 struct mutex lun_entry_mutex;
c66ac9db
NB
570 spinlock_t nacl_sess_lock;
571 struct config_group acl_group;
572 struct config_group acl_attrib_group;
573 struct config_group acl_auth_group;
574 struct config_group acl_param_group;
12d23384
NB
575 struct config_group acl_fabric_stat_group;
576 struct config_group *acl_default_groups[5];
c66ac9db
NB
577 struct list_head acl_list;
578 struct list_head acl_sess_list;
01468346 579 struct completion acl_free_comp;
afb999ff 580 struct kref acl_kref;
e0a53e70 581};
c66ac9db
NB
582
583struct se_session {
5f655e8d 584 unsigned sess_tearing_down:1;
c66ac9db 585 u64 sess_bin_isid;
e70beee7 586 enum target_prot_op sup_prot_ops;
38b57f82 587 enum target_prot_type sess_prot_type;
c66ac9db
NB
588 struct se_node_acl *se_node_acl;
589 struct se_portal_group *se_tpg;
590 void *fabric_sess_ptr;
591 struct list_head sess_list;
592 struct list_head sess_acl_list;
a17f091d 593 struct list_head sess_cmd_list;
9b31a328 594 struct list_head sess_wait_list;
a17f091d 595 spinlock_t sess_cmd_lock;
41ac82b6 596 struct kref sess_kref;
c0add7fd
NB
597 void *sess_cmd_map;
598 struct percpu_ida sess_tag_pool;
e0a53e70 599};
c66ac9db 600
c66ac9db
NB
601struct se_device;
602struct se_transform_info;
603struct scatterlist;
604
12d23384
NB
605struct se_ml_stat_grps {
606 struct config_group stat_group;
607 struct config_group scsi_auth_intr_group;
608 struct config_group scsi_att_intr_port_group;
609};
610
c66ac9db
NB
611struct se_lun_acl {
612 char initiatorname[TRANSPORT_IQN_LEN];
f2d30680 613 u64 mapped_lun;
c66ac9db
NB
614 struct se_node_acl *se_lun_nacl;
615 struct se_lun *se_lun;
c66ac9db 616 struct config_group se_lun_group;
12d23384 617 struct se_ml_stat_grps ml_stat_grps;
e0a53e70 618};
c66ac9db
NB
619
620struct se_dev_entry {
c66ac9db 621 /* See transport_lunflags_table */
f2d30680 622 u64 mapped_lun;
c66ac9db
NB
623 u64 pr_res_key;
624 u64 creation_time;
f2d30680 625 u32 lun_flags;
c66ac9db 626 u32 attach_count;
29a05dee
NB
627 atomic_long_t total_cmds;
628 atomic_long_t read_bytes;
629 atomic_long_t write_bytes;
c66ac9db
NB
630 atomic_t ua_count;
631 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
29a05dee
NB
632 struct kref pr_kref;
633 struct completion pr_comp;
634 struct se_lun_acl __rcu *se_lun_acl;
c66ac9db 635 spinlock_t ua_lock;
29a05dee 636 struct se_lun __rcu *se_lun;
80bfdfa9
NB
637#define DEF_PR_REG_ACTIVE 1
638 unsigned long deve_flags;
c66ac9db 639 struct list_head alua_port_list;
adf653f9 640 struct list_head lun_link;
c66ac9db 641 struct list_head ua_list;
29a05dee
NB
642 struct hlist_node link;
643 struct rcu_head rcu_head;
e0a53e70 644};
c66ac9db 645
c66ac9db 646struct se_dev_attrib {
adfa9570 647 int emulate_model_alias;
c66ac9db
NB
648 int emulate_dpo;
649 int emulate_fua_write;
650 int emulate_fua_read;
651 int emulate_write_cache;
652 int emulate_ua_intlck_ctrl;
653 int emulate_tas;
654 int emulate_tpu;
655 int emulate_tpws;
0123a9ec 656 int emulate_caw;
d397a445 657 int emulate_3pc;
ce65e5b9
NB
658 int pi_prot_format;
659 enum target_prot_type pi_prot_type;
660 enum target_prot_type hw_pi_prot_type;
c66ac9db 661 int enforce_pr_isids;
92404e60 662 int force_pr_aptpl;
e22a7f07 663 int is_nonrot;
5de619a3 664 int emulate_rest_reord;
c66ac9db
NB
665 u32 hw_block_size;
666 u32 block_size;
667 u32 hw_max_sectors;
c66ac9db
NB
668 u32 optimal_sectors;
669 u32 hw_queue_depth;
670 u32 queue_depth;
c66ac9db
NB
671 u32 max_unmap_lba_count;
672 u32 max_unmap_block_desc_count;
673 u32 unmap_granularity;
674 u32 unmap_granularity_alignment;
773cbaf7 675 u32 max_write_same_len;
95cadace 676 u32 max_bytes_per_io;
0fd97ccf 677 struct se_device *da_dev;
c66ac9db 678 struct config_group da_group;
e0a53e70 679};
c66ac9db 680
4863e525
NB
681struct se_port_stat_grps {
682 struct config_group stat_group;
683 struct config_group scsi_port_group;
684 struct config_group scsi_tgt_port_group;
685 struct config_group scsi_transport_group;
686};
687
adf653f9 688struct scsi_port_stats {
4cc987ea
NB
689 atomic_long_t cmd_pdus;
690 atomic_long_t tx_data_octets;
691 atomic_long_t rx_data_octets;
adf653f9
CH
692};
693
4863e525 694struct se_lun {
f2d30680 695 u64 unpacked_lun;
4863e525
NB
696#define SE_LUN_LINK_MAGIC 0xffff7771
697 u32 lun_link_magic;
4863e525
NB
698 u32 lun_access;
699 u32 lun_flags;
29a05dee 700 u32 lun_index;
f2d30680
HR
701
702 /* RELATIVE TARGET PORT IDENTIFER */
703 u16 lun_rtpi;
4863e525 704 atomic_t lun_acl_count;
adf653f9
CH
705 struct se_device __rcu *lun_se_dev;
706
707 struct list_head lun_deve_list;
708 spinlock_t lun_deve_lock;
709
710 /* ALUA state */
711 int lun_tg_pt_secondary_stat;
712 int lun_tg_pt_secondary_write_md;
713 atomic_t lun_tg_pt_secondary_offline;
714 struct mutex lun_tg_pt_md_mutex;
715
716 /* ALUA target port group linkage */
717 struct list_head lun_tg_pt_gp_link;
718 struct t10_alua_tg_pt_gp *lun_tg_pt_gp;
719 spinlock_t lun_tg_pt_gp_lock;
720
adf653f9
CH
721 struct se_portal_group *lun_tpg;
722 struct scsi_port_stats lun_stats;
4863e525
NB
723 struct config_group lun_group;
724 struct se_port_stat_grps port_stat_grps;
725 struct completion lun_ref_comp;
726 struct percpu_ref lun_ref;
adf653f9 727 struct list_head lun_dev_link;
6bb82612
NB
728 struct hlist_node link;
729 struct rcu_head rcu_head;
4863e525
NB
730};
731
12d23384
NB
732struct se_dev_stat_grps {
733 struct config_group stat_group;
734 struct config_group scsi_dev_group;
735 struct config_group scsi_tgt_dev_group;
736 struct config_group scsi_lu_group;
737};
738
c66ac9db 739struct se_device {
0ff87549
NB
740#define SE_DEV_LINK_MAGIC 0xfeeddeef
741 u32 dev_link_magic;
c66ac9db
NB
742 /* RELATIVE TARGET PORT IDENTIFER Counter */
743 u16 dev_rpti_counter;
744 /* Used for SAM Task Attribute ordering */
745 u32 dev_cur_ordered_id;
746 u32 dev_flags;
0fd97ccf
CH
747#define DF_CONFIGURED 0x00000001
748#define DF_FIRMWARE_VPD_UNIT_SERIAL 0x00000002
749#define DF_EMULATED_VPD_UNIT_SERIAL 0x00000004
750#define DF_USING_UDEV_PATH 0x00000008
751#define DF_USING_ALIAS 0x00000010
c66ac9db
NB
752 /* Physical device queue depth */
753 u32 queue_depth;
754 /* Used for SPC-2 reservations enforce of ISIDs */
755 u64 dev_res_bin_isid;
c66ac9db 756 /* Pointer to transport specific device structure */
c66ac9db
NB
757 u32 dev_index;
758 u64 creation_time;
ee480683
NB
759 atomic_long_t num_resets;
760 atomic_long_t num_cmds;
761 atomic_long_t read_bytes;
762 atomic_long_t write_bytes;
c66ac9db 763 /* Active commands on this virtual SE device */
c66ac9db 764 atomic_t simple_cmds;
c66ac9db 765 atomic_t dev_ordered_id;
c66ac9db 766 atomic_t dev_ordered_sync;
07bde79a 767 atomic_t dev_qf_count;
adf653f9 768 u32 export_count;
c66ac9db 769 spinlock_t delayed_cmd_lock;
c66ac9db 770 spinlock_t execute_task_lock;
c66ac9db 771 spinlock_t dev_reservation_lock;
0fd97ccf
CH
772 unsigned int dev_reservation_flags;
773#define DRF_SPC2_RESERVATIONS 0x00000001
774#define DRF_SPC2_RESERVATIONS_WITH_ISID 0x00000002
c66ac9db
NB
775 spinlock_t se_port_lock;
776 spinlock_t se_tmr_lock;
07bde79a 777 spinlock_t qf_cmd_lock;
68ff9b9b 778 struct semaphore caw_sem;
c66ac9db
NB
779 /* Used for legacy SPC-2 reservationsa */
780 struct se_node_acl *dev_reserved_node_acl;
781 /* Used for ALUA Logical Unit Group membership */
782 struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
783 /* Used for SPC-3 Persistent Reservations */
784 struct t10_pr_registration *dev_pr_res_holder;
785 struct list_head dev_sep_list;
786 struct list_head dev_tmr_list;
af877292 787 struct workqueue_struct *tmr_wq;
07bde79a 788 struct work_struct qf_work_queue;
c66ac9db 789 struct list_head delayed_cmd_list;
cf572a96 790 struct list_head state_list;
07bde79a 791 struct list_head qf_cmd_list;
d9ea32bf 792 struct list_head g_dev_node;
c66ac9db
NB
793 /* Pointer to associated SE HBA */
794 struct se_hba *se_hba;
0fd97ccf
CH
795 /* T10 Inquiry and VPD WWN Information */
796 struct t10_wwn t10_wwn;
797 /* T10 Asymmetric Logical Unit Assignment for Target Ports */
798 struct t10_alua t10_alua;
799 /* T10 SPC-2 + SPC-3 Reservations */
800 struct t10_reservation t10_pr;
801 struct se_dev_attrib dev_attrib;
802 struct config_group dev_group;
803 struct config_group dev_pr_group;
804 struct se_dev_stat_grps dev_stat_grps;
805#define SE_DEV_ALIAS_LEN 512 /* must be less than PAGE_SIZE */
806 unsigned char dev_alias[SE_DEV_ALIAS_LEN];
807#define SE_UDEV_PATH_LEN 512 /* must be less than PAGE_SIZE */
808 unsigned char udev_path[SE_UDEV_PATH_LEN];
c66ac9db 809 /* Pointer to template of function pointers for transport */
0a06d430 810 const struct target_backend_ops *transport;
c66ac9db
NB
811 /* Linked list for struct se_hba struct se_device list */
812 struct list_head dev_list;
4863e525 813 struct se_lun xcopy_lun;
ce65e5b9
NB
814 /* Protection Information */
815 int prot_length;
4cc987ea
NB
816 /* For se_lun->lun_se_dev RCU read-side critical access */
817 u32 hba_index;
818 struct rcu_head rcu_head;
e0a53e70 819};
c66ac9db 820
c66ac9db
NB
821struct se_hba {
822 u16 hba_tpgt;
823 u32 hba_id;
824 /* See hba_flags_table */
825 u32 hba_flags;
826 /* Virtual iSCSI devices attached. */
827 u32 dev_count;
828 u32 hba_index;
c66ac9db
NB
829 /* Pointer to transport specific host structure. */
830 void *hba_ptr;
e3d6f909 831 struct list_head hba_node;
c66ac9db 832 spinlock_t device_lock;
c66ac9db
NB
833 struct config_group hba_group;
834 struct mutex hba_access_mutex;
0a06d430 835 struct target_backend *backend;
e0a53e70 836};
c66ac9db 837
c66ac9db 838struct se_tpg_np {
1f6fe7cb 839 struct se_portal_group *tpg_np_parent;
c66ac9db 840 struct config_group tpg_np_group;
e0a53e70 841};
c66ac9db
NB
842
843struct se_portal_group {
e4aae5af
CH
844 /*
845 * PROTOCOL IDENTIFIER value per SPC4, 7.5.1.
846 *
847 * Negative values can be used by fabric drivers for internal use TPGs.
848 */
849 int proto_id;
c66ac9db
NB
850 /* Number of ACLed Initiator Nodes for this TPG */
851 u32 num_node_acls;
852 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
853 atomic_t tpg_pr_ref_count;
854 /* Spinlock for adding/removing ACLed Nodes */
403edd78 855 struct mutex acl_node_mutex;
c66ac9db
NB
856 /* Spinlock for adding/removing sessions */
857 spinlock_t session_lock;
6bb82612 858 struct mutex tpg_lun_mutex;
e3d6f909 859 struct list_head se_tpg_node;
c66ac9db
NB
860 /* linked list for initiator ACL list */
861 struct list_head acl_node_list;
6bb82612 862 struct hlist_head tpg_lun_hlist;
adf653f9 863 struct se_lun *tpg_virt_lun0;
25985edc 864 /* List of TCM sessions associated wth this TPG */
c66ac9db
NB
865 struct list_head tpg_sess_list;
866 /* Pointer to $FABRIC_MOD dependent code */
9ac8928e 867 const struct target_core_fabric_ops *se_tpg_tfo;
c66ac9db
NB
868 struct se_wwn *se_tpg_wwn;
869 struct config_group tpg_group;
e4b512e7 870 struct config_group *tpg_default_groups[7];
c66ac9db
NB
871 struct config_group tpg_lun_group;
872 struct config_group tpg_np_group;
873 struct config_group tpg_acl_group;
874 struct config_group tpg_attrib_group;
e4b512e7 875 struct config_group tpg_auth_group;
c66ac9db 876 struct config_group tpg_param_group;
e0a53e70 877};
c66ac9db 878
c66ac9db
NB
879struct se_wwn {
880 struct target_fabric_configfs *wwn_tf;
881 struct config_group wwn_group;
12d23384
NB
882 struct config_group *wwn_default_groups[2];
883 struct config_group fabric_stat_group;
e0a53e70 884};
c66ac9db 885
33940d09
JE
886static inline void atomic_inc_mb(atomic_t *v)
887{
888 smp_mb__before_atomic();
889 atomic_inc(v);
890 smp_mb__after_atomic();
891}
892
893static inline void atomic_dec_mb(atomic_t *v)
894{
895 smp_mb__before_atomic();
896 atomic_dec(v);
897 smp_mb__after_atomic();
898}
899
c66ac9db 900#endif /* TARGET_CORE_BASE_H */