Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef TARGET_CORE_BASE_H
0003 #define TARGET_CORE_BASE_H
0004 
0005 #include <linux/configfs.h>      /* struct config_group */
0006 #include <linux/dma-direction.h> /* enum dma_data_direction */
0007 #include <linux/sbitmap.h>
0008 #include <linux/percpu-refcount.h>
0009 #include <linux/semaphore.h>     /* struct semaphore */
0010 #include <linux/completion.h>
0011 
0012 #define TARGET_CORE_VERSION     "v5.0"
0013 
0014 /*
0015  * Maximum size of a CDB that can be stored in se_cmd without allocating
0016  * memory dynamically for the CDB.
0017  */
0018 #define TCM_MAX_COMMAND_SIZE            32
0019 /*
0020  * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
0021  * defined 96, but the real limit is 252 (or 260 including the header)
0022  */
0023 #define TRANSPORT_SENSE_BUFFER          96
0024 /* Used by transport_send_check_condition_and_sense() */
0025 #define SPC_SENSE_KEY_OFFSET            2
0026 #define SPC_ADD_SENSE_LEN_OFFSET        7
0027 #define SPC_DESC_TYPE_OFFSET            8
0028 #define SPC_ADDITIONAL_DESC_LEN_OFFSET      9
0029 #define SPC_VALIDITY_OFFSET         10
0030 #define SPC_ASC_KEY_OFFSET          12
0031 #define SPC_ASCQ_KEY_OFFSET         13
0032 #define TRANSPORT_IQN_LEN           224
0033 /* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
0034 #define LU_GROUP_NAME_BUF           256
0035 /* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
0036 #define TG_PT_GROUP_NAME_BUF            256
0037 /* Used to parse VPD into struct t10_vpd */
0038 #define VPD_TMP_BUF_SIZE            254
0039 /* Used by transport_generic_cmd_sequencer() */
0040 #define READ_BLOCK_LEN                  6
0041 #define READ_CAP_LEN                    8
0042 #define READ_POSITION_LEN               20
0043 #define INQUIRY_LEN             36
0044 /* Used by transport_get_inquiry_vpd_serial() */
0045 #define INQUIRY_VPD_SERIAL_LEN          254
0046 /* Used by transport_get_inquiry_vpd_device_ident() */
0047 #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN   254
0048 
0049 #define INQUIRY_VENDOR_LEN          8
0050 #define INQUIRY_MODEL_LEN           16
0051 #define INQUIRY_REVISION_LEN            4
0052 
0053 /* Attempts before moving from SHORT to LONG */
0054 #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD   3
0055 #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT  3  /* In milliseconds */
0056 #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG   10 /* In milliseconds */
0057 
0058 #define PYX_TRANSPORT_STATUS_INTERVAL       5 /* In seconds */
0059 
0060 /* struct se_dev_attrib sanity values */
0061 /* Default max_unmap_lba_count */
0062 #define DA_MAX_UNMAP_LBA_COUNT          0
0063 /* Default max_unmap_block_desc_count */
0064 #define DA_MAX_UNMAP_BLOCK_DESC_COUNT       0
0065 /* Default unmap_granularity */
0066 #define DA_UNMAP_GRANULARITY_DEFAULT        0
0067 /* Default unmap_granularity_alignment */
0068 #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT  0
0069 /* Default unmap_zeroes_data */
0070 #define DA_UNMAP_ZEROES_DATA_DEFAULT        0
0071 /* Default max_write_same_len, disabled by default */
0072 #define DA_MAX_WRITE_SAME_LEN           0
0073 /* Use a model alias based on the configfs backend device name */
0074 #define DA_EMULATE_MODEL_ALIAS          0
0075 /* Emulation for WriteCache and SYNCHRONIZE_CACHE */
0076 #define DA_EMULATE_WRITE_CACHE          0
0077 /* Emulation for TASK_ABORTED status (TAS) by default */
0078 #define DA_EMULATE_TAS              1
0079 /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
0080 #define DA_EMULATE_TPU              0
0081 /*
0082  * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
0083  * block/blk-lib.c:blkdev_issue_discard()
0084  */
0085 #define DA_EMULATE_TPWS             0
0086 /* Emulation for CompareAndWrite (AtomicTestandSet) by default */
0087 #define DA_EMULATE_CAW              1
0088 /* Emulation for 3rd Party Copy (ExtendedCopy) by default */
0089 #define DA_EMULATE_3PC              1
0090 /* No Emulation for PSCSI by default */
0091 #define DA_EMULATE_ALUA             0
0092 /* Emulate SCSI2 RESERVE/RELEASE and Persistent Reservations by default */
0093 #define DA_EMULATE_PR               1
0094 /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
0095 #define DA_ENFORCE_PR_ISIDS         1
0096 /* Force SPC-3 PR Activate Persistence across Target Power Loss */
0097 #define DA_FORCE_PR_APTPL           0
0098 #define DA_STATUS_MAX_SECTORS_MIN       16
0099 #define DA_STATUS_MAX_SECTORS_MAX       8192
0100 /* By default don't report non-rotating (solid state) medium */
0101 #define DA_IS_NONROT                0
0102 /* Queue Algorithm Modifier default for restricted reordering in control mode page */
0103 #define DA_EMULATE_REST_REORD           0
0104 
0105 #define SE_INQUIRY_BUF              1024
0106 #define SE_MODE_PAGE_BUF            512
0107 #define SE_SENSE_BUF                96
0108 
0109 /* struct se_hba->hba_flags */
0110 enum hba_flags_table {
0111     HBA_FLAGS_INTERNAL_USE  = 0x01,
0112     HBA_FLAGS_PSCSI_MODE    = 0x02,
0113 };
0114 
0115 /* Special transport agnostic struct se_cmd->t_states */
0116 enum transport_state_table {
0117     TRANSPORT_NO_STATE  = 0,
0118     TRANSPORT_NEW_CMD   = 1,
0119     TRANSPORT_WRITE_PENDING = 3,
0120     TRANSPORT_PROCESSING    = 5,
0121     TRANSPORT_COMPLETE  = 6,
0122     TRANSPORT_ISTATE_PROCESSING = 11,
0123     TRANSPORT_COMPLETE_QF_WP = 18,
0124     TRANSPORT_COMPLETE_QF_OK = 19,
0125     TRANSPORT_COMPLETE_QF_ERR = 20,
0126 };
0127 
0128 /* Used for struct se_cmd->se_cmd_flags */
0129 enum se_cmd_flags_table {
0130     SCF_SUPPORTED_SAM_OPCODE        = (1 << 0),
0131     SCF_TRANSPORT_TASK_SENSE        = (1 << 1),
0132     SCF_EMULATED_TASK_SENSE         = (1 << 2),
0133     SCF_SCSI_DATA_CDB           = (1 << 3),
0134     SCF_SCSI_TMR_CDB            = (1 << 4),
0135     SCF_FUA                 = (1 << 5),
0136     SCF_SE_LUN_CMD              = (1 << 6),
0137     SCF_BIDI                = (1 << 7),
0138     SCF_SENT_CHECK_CONDITION        = (1 << 8),
0139     SCF_OVERFLOW_BIT            = (1 << 9),
0140     SCF_UNDERFLOW_BIT           = (1 << 10),
0141     SCF_ALUA_NON_OPTIMIZED          = (1 << 11),
0142     SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC   = (1 << 12),
0143     SCF_COMPARE_AND_WRITE           = (1 << 13),
0144     SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC  = (1 << 14),
0145     SCF_ACK_KREF                = (1 << 15),
0146     SCF_USE_CPUID               = (1 << 16),
0147     SCF_TASK_ATTR_SET           = (1 << 17),
0148     SCF_TREAT_READ_AS_NORMAL        = (1 << 18),
0149 };
0150 
0151 /*
0152  * Used by transport_send_check_condition_and_sense()
0153  * to signal which ASC/ASCQ sense payload should be built.
0154  */
0155 typedef unsigned __bitwise sense_reason_t;
0156 
0157 enum tcm_sense_reason_table {
0158 #define R(x)    (__force sense_reason_t )(x)
0159     TCM_NO_SENSE                = R(0x00),
0160     TCM_NON_EXISTENT_LUN            = R(0x01),
0161     TCM_UNSUPPORTED_SCSI_OPCODE     = R(0x02),
0162     TCM_INCORRECT_AMOUNT_OF_DATA        = R(0x03),
0163     TCM_UNEXPECTED_UNSOLICITED_DATA     = R(0x04),
0164     TCM_SERVICE_CRC_ERROR           = R(0x05),
0165     TCM_SNACK_REJECTED          = R(0x06),
0166     TCM_SECTOR_COUNT_TOO_MANY       = R(0x07),
0167     TCM_INVALID_CDB_FIELD           = R(0x08),
0168     TCM_INVALID_PARAMETER_LIST      = R(0x09),
0169     TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE  = R(0x0a),
0170     TCM_UNKNOWN_MODE_PAGE           = R(0x0b),
0171     TCM_WRITE_PROTECTED         = R(0x0c),
0172     TCM_CHECK_CONDITION_ABORT_CMD       = R(0x0d),
0173     TCM_CHECK_CONDITION_UNIT_ATTENTION  = R(0x0e),
0174 
0175     TCM_RESERVATION_CONFLICT        = R(0x10),
0176     TCM_ADDRESS_OUT_OF_RANGE        = R(0x11),
0177     TCM_OUT_OF_RESOURCES            = R(0x12),
0178     TCM_PARAMETER_LIST_LENGTH_ERROR     = R(0x13),
0179     TCM_MISCOMPARE_VERIFY           = R(0x14),
0180     TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED    = R(0x15),
0181     TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED  = R(0x16),
0182     TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED  = R(0x17),
0183     TCM_COPY_TARGET_DEVICE_NOT_REACHABLE    = R(0x18),
0184     TCM_TOO_MANY_TARGET_DESCS       = R(0x19),
0185     TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE   = R(0x1a),
0186     TCM_TOO_MANY_SEGMENT_DESCS      = R(0x1b),
0187     TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE  = R(0x1c),
0188     TCM_INSUFFICIENT_REGISTRATION_RESOURCES = R(0x1d),
0189     TCM_LUN_BUSY                = R(0x1e),
0190     TCM_INVALID_FIELD_IN_COMMAND_IU         = R(0x1f),
0191     TCM_ALUA_TG_PT_STANDBY          = R(0x20),
0192     TCM_ALUA_TG_PT_UNAVAILABLE      = R(0x21),
0193     TCM_ALUA_STATE_TRANSITION       = R(0x22),
0194     TCM_ALUA_OFFLINE            = R(0x23),
0195 #undef R
0196 };
0197 
0198 enum target_sc_flags_table {
0199     TARGET_SCF_BIDI_OP      = 0x01,
0200     TARGET_SCF_ACK_KREF     = 0x02,
0201     TARGET_SCF_UNKNOWN_SIZE     = 0x04,
0202     TARGET_SCF_USE_CPUID        = 0x08,
0203 };
0204 
0205 /* fabric independent task management function values */
0206 enum tcm_tmreq_table {
0207     TMR_ABORT_TASK      = 1,
0208     TMR_ABORT_TASK_SET  = 2,
0209     TMR_CLEAR_ACA       = 3,
0210     TMR_CLEAR_TASK_SET  = 4,
0211     TMR_LUN_RESET       = 5,
0212     TMR_TARGET_WARM_RESET   = 6,
0213     TMR_TARGET_COLD_RESET   = 7,
0214     TMR_LUN_RESET_PRO   = 0x80,
0215     TMR_UNKNOWN     = 0xff,
0216 };
0217 
0218 /* fabric independent task management response values */
0219 enum tcm_tmrsp_table {
0220     TMR_FUNCTION_FAILED     = 0,
0221     TMR_FUNCTION_COMPLETE       = 1,
0222     TMR_TASK_DOES_NOT_EXIST     = 2,
0223     TMR_LUN_DOES_NOT_EXIST      = 3,
0224     TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED    = 4,
0225     TMR_FUNCTION_REJECTED       = 5,
0226 };
0227 
0228 /*
0229  * Used for target SCSI statistics
0230  */
0231 typedef enum {
0232     SCSI_INST_INDEX,
0233     SCSI_AUTH_INTR_INDEX,
0234     SCSI_INDEX_TYPE_MAX
0235 } scsi_index_t;
0236 
0237 struct se_cmd;
0238 
0239 struct t10_alua_lba_map_member {
0240     struct list_head lba_map_mem_list;
0241     int lba_map_mem_alua_state;
0242     int lba_map_mem_alua_pg_id;
0243 };
0244 
0245 struct t10_alua_lba_map {
0246     u64 lba_map_first_lba;
0247     u64 lba_map_last_lba;
0248     struct list_head lba_map_list;
0249     struct list_head lba_map_mem_list;
0250 };
0251 
0252 struct t10_alua {
0253     /* ALUA Target Port Group ID */
0254     u16 alua_tg_pt_gps_counter;
0255     u32 alua_tg_pt_gps_count;
0256     /* Referrals support */
0257     spinlock_t lba_map_lock;
0258     u32     lba_map_segment_size;
0259     u32     lba_map_segment_multiplier;
0260     struct list_head lba_map_list;
0261     spinlock_t tg_pt_gps_lock;
0262     struct se_device *t10_dev;
0263     /* Used for default ALUA Target Port Group */
0264     struct t10_alua_tg_pt_gp *default_tg_pt_gp;
0265     /* Used for default ALUA Target Port Group ConfigFS group */
0266     struct config_group alua_tg_pt_gps_group;
0267     struct list_head tg_pt_gps_list;
0268 };
0269 
0270 struct t10_alua_lu_gp {
0271     u16 lu_gp_id;
0272     int lu_gp_valid_id;
0273     u32 lu_gp_members;
0274     atomic_t lu_gp_ref_cnt;
0275     spinlock_t lu_gp_lock;
0276     struct config_group lu_gp_group;
0277     struct list_head lu_gp_node;
0278     struct list_head lu_gp_mem_list;
0279 };
0280 
0281 struct t10_alua_lu_gp_member {
0282     bool lu_gp_assoc;
0283     atomic_t lu_gp_mem_ref_cnt;
0284     spinlock_t lu_gp_mem_lock;
0285     struct t10_alua_lu_gp *lu_gp;
0286     struct se_device *lu_gp_mem_dev;
0287     struct list_head lu_gp_mem_list;
0288 };
0289 
0290 struct t10_alua_tg_pt_gp {
0291     u16 tg_pt_gp_id;
0292     int tg_pt_gp_valid_id;
0293     int tg_pt_gp_alua_supported_states;
0294     int tg_pt_gp_alua_access_status;
0295     int tg_pt_gp_alua_access_type;
0296     int tg_pt_gp_nonop_delay_msecs;
0297     int tg_pt_gp_trans_delay_msecs;
0298     int tg_pt_gp_implicit_trans_secs;
0299     int tg_pt_gp_pref;
0300     int tg_pt_gp_write_metadata;
0301     u32 tg_pt_gp_members;
0302     int tg_pt_gp_alua_access_state;
0303     atomic_t tg_pt_gp_ref_cnt;
0304     spinlock_t tg_pt_gp_lock;
0305     struct mutex tg_pt_gp_transition_mutex;
0306     struct se_device *tg_pt_gp_dev;
0307     struct config_group tg_pt_gp_group;
0308     struct list_head tg_pt_gp_list;
0309     struct list_head tg_pt_gp_lun_list;
0310     struct se_lun *tg_pt_gp_alua_lun;
0311     struct se_node_acl *tg_pt_gp_alua_nacl;
0312 };
0313 
0314 struct t10_vpd {
0315     unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
0316     int protocol_identifier_set;
0317     u32 protocol_identifier;
0318     u32 device_identifier_code_set;
0319     u32 association;
0320     u32 device_identifier_type;
0321     struct list_head vpd_list;
0322 };
0323 
0324 struct t10_wwn {
0325     /*
0326      * SCSI left aligned strings may not be null terminated. +1 to ensure a
0327      * null terminator is always present.
0328      */
0329     char vendor[INQUIRY_VENDOR_LEN + 1];
0330     char model[INQUIRY_MODEL_LEN + 1];
0331     char revision[INQUIRY_REVISION_LEN + 1];
0332     char unit_serial[INQUIRY_VPD_SERIAL_LEN];
0333     u32 company_id;
0334     spinlock_t t10_vpd_lock;
0335     struct se_device *t10_dev;
0336     struct config_group t10_wwn_group;
0337     struct list_head t10_vpd_list;
0338 };
0339 
0340 struct t10_pr_registration {
0341     /* Used for fabrics that contain WWN+ISID */
0342 #define PR_REG_ISID_LEN             16
0343     /* PR_REG_ISID_LEN + ',i,0x' */
0344 #define PR_REG_ISID_ID_LEN          (PR_REG_ISID_LEN + 5)
0345     char pr_reg_isid[PR_REG_ISID_LEN];
0346     /* Used during APTPL metadata reading */
0347 #define PR_APTPL_MAX_IPORT_LEN          256
0348     unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
0349     /* Used during APTPL metadata reading */
0350 #define PR_APTPL_MAX_TPORT_LEN          256
0351     unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
0352     u16 pr_aptpl_rpti;
0353     u16 pr_reg_tpgt;
0354     /* Reservation effects all target ports */
0355     int pr_reg_all_tg_pt;
0356     /* Activate Persistence across Target Power Loss */
0357     int pr_reg_aptpl;
0358     int pr_res_holder;
0359     int pr_res_type;
0360     int pr_res_scope;
0361     /* Used for fabric initiator WWPNs using a ISID */
0362     bool isid_present_at_reg;
0363     u64 pr_res_mapped_lun;
0364     u64 pr_aptpl_target_lun;
0365     u16 tg_pt_sep_rtpi;
0366     u32 pr_res_generation;
0367     u64 pr_reg_bin_isid;
0368     u64 pr_res_key;
0369     atomic_t pr_res_holders;
0370     struct se_node_acl *pr_reg_nacl;
0371     /* Used by ALL_TG_PT=1 registration with deve->pr_ref taken */
0372     struct se_dev_entry *pr_reg_deve;
0373     struct list_head pr_reg_list;
0374     struct list_head pr_reg_abort_list;
0375     struct list_head pr_reg_aptpl_list;
0376     struct list_head pr_reg_atp_list;
0377     struct list_head pr_reg_atp_mem_list;
0378 };
0379 
0380 struct t10_reservation {
0381     /* Reservation effects all target ports */
0382     int pr_all_tg_pt;
0383     /* Activate Persistence across Target Power Loss enabled
0384      * for SCSI device */
0385     int pr_aptpl_active;
0386 #define PR_APTPL_BUF_LEN            262144
0387     u32 pr_generation;
0388     spinlock_t registration_lock;
0389     spinlock_t aptpl_reg_lock;
0390     /*
0391      * This will always be set by one individual I_T Nexus.
0392      * However with all_tg_pt=1, other I_T Nexus from the
0393      * same initiator can access PR reg/res info on a different
0394      * target port.
0395      *
0396      * There is also the 'All Registrants' case, where there is
0397      * a single *pr_res_holder of the reservation, but all
0398      * registrations are considered reservation holders.
0399      */
0400     struct se_node_acl *pr_res_holder;
0401     struct list_head registration_list;
0402     struct list_head aptpl_reg_list;
0403 };
0404 
0405 struct se_tmr_req {
0406     /* Task Management function to be performed */
0407     u8          function;
0408     /* Task Management response to send */
0409     u8          response;
0410     int         call_transport;
0411     /* Reference to ITT that Task Mgmt should be performed */
0412     u64         ref_task_tag;
0413     void            *fabric_tmr_ptr;
0414     struct se_cmd       *task_cmd;
0415     struct se_device    *tmr_dev;
0416     struct list_head    tmr_list;
0417 };
0418 
0419 enum target_prot_op {
0420     TARGET_PROT_NORMAL  = 0,
0421     TARGET_PROT_DIN_INSERT  = (1 << 0),
0422     TARGET_PROT_DOUT_INSERT = (1 << 1),
0423     TARGET_PROT_DIN_STRIP   = (1 << 2),
0424     TARGET_PROT_DOUT_STRIP  = (1 << 3),
0425     TARGET_PROT_DIN_PASS    = (1 << 4),
0426     TARGET_PROT_DOUT_PASS   = (1 << 5),
0427 };
0428 
0429 #define TARGET_PROT_ALL TARGET_PROT_DIN_INSERT | TARGET_PROT_DOUT_INSERT | \
0430             TARGET_PROT_DIN_STRIP | TARGET_PROT_DOUT_STRIP | \
0431             TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS
0432 
0433 enum target_prot_type {
0434     TARGET_DIF_TYPE0_PROT,
0435     TARGET_DIF_TYPE1_PROT,
0436     TARGET_DIF_TYPE2_PROT,
0437     TARGET_DIF_TYPE3_PROT,
0438 };
0439 
0440 /* Emulation for UNIT ATTENTION Interlock Control */
0441 enum target_ua_intlck_ctrl {
0442     TARGET_UA_INTLCK_CTRL_CLEAR = 0,
0443     TARGET_UA_INTLCK_CTRL_NO_CLEAR = 1,
0444     TARGET_UA_INTLCK_CTRL_ESTABLISH_UA = 2,
0445 };
0446 
0447 enum target_core_dif_check {
0448     TARGET_DIF_CHECK_GUARD  = 0x1 << 0,
0449     TARGET_DIF_CHECK_APPTAG = 0x1 << 1,
0450     TARGET_DIF_CHECK_REFTAG = 0x1 << 2,
0451 };
0452 
0453 /* for sam_task_attr */
0454 #define TCM_SIMPLE_TAG  0x20
0455 #define TCM_HEAD_TAG    0x21
0456 #define TCM_ORDERED_TAG 0x22
0457 #define TCM_ACA_TAG 0x24
0458 
0459 struct se_cmd {
0460     /* Used for fail with specific sense codes */
0461     sense_reason_t      sense_reason;
0462     /* SAM response code being sent to initiator */
0463     u8          scsi_status;
0464     u16         scsi_sense_length;
0465     unsigned        unknown_data_length:1;
0466     bool            state_active:1;
0467     u64         tag; /* SAM command identifier aka task tag */
0468     /* Delay for ALUA Active/NonOptimized state access in milliseconds */
0469     int         alua_nonop_delay;
0470     /* See include/linux/dma-mapping.h */
0471     enum dma_data_direction data_direction;
0472     /* For SAM Task Attribute */
0473     int         sam_task_attr;
0474     /* Used for se_sess->sess_tag_pool */
0475     unsigned int        map_tag;
0476     int         map_cpu;
0477     /* Transport protocol dependent state, see transport_state_table */
0478     enum transport_state_table t_state;
0479     /* See se_cmd_flags_table */
0480     u32         se_cmd_flags;
0481     /* Total size in bytes associated with command */
0482     u32         data_length;
0483     u32         residual_count;
0484     u64         orig_fe_lun;
0485     /* Persistent Reservation key */
0486     u64         pr_res_key;
0487     /* Used for sense data */
0488     void            *sense_buffer;
0489     struct list_head    se_delayed_node;
0490     struct list_head    se_qf_node;
0491     struct se_device      *se_dev;
0492     struct se_lun       *se_lun;
0493     /* Only used for internal passthrough and legacy TCM fabric modules */
0494     struct se_session   *se_sess;
0495     struct se_tmr_req   *se_tmr_req;
0496     struct llist_node   se_cmd_list;
0497     struct completion   *free_compl;
0498     struct completion   *abrt_compl;
0499     const struct target_core_fabric_ops *se_tfo;
0500     sense_reason_t      (*execute_cmd)(struct se_cmd *);
0501     sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool, int *);
0502     void            *protocol_data;
0503 
0504     unsigned char       *t_task_cdb;
0505     unsigned char       __t_task_cdb[TCM_MAX_COMMAND_SIZE];
0506     unsigned long long  t_task_lba;
0507     unsigned int        t_task_nolb;
0508     unsigned int        transport_state;
0509 #define CMD_T_ABORTED       (1 << 0)
0510 #define CMD_T_ACTIVE        (1 << 1)
0511 #define CMD_T_COMPLETE      (1 << 2)
0512 #define CMD_T_SENT      (1 << 4)
0513 #define CMD_T_STOP      (1 << 5)
0514 #define CMD_T_TAS       (1 << 10)
0515 #define CMD_T_FABRIC_STOP   (1 << 11)
0516     spinlock_t      t_state_lock;
0517     struct kref     cmd_kref;
0518     struct completion   t_transport_stop_comp;
0519 
0520     struct work_struct  work;
0521 
0522     struct scatterlist  *t_data_sg;
0523     struct scatterlist  *t_data_sg_orig;
0524     unsigned int        t_data_nents;
0525     unsigned int        t_data_nents_orig;
0526     void            *t_data_vmap;
0527     struct scatterlist  *t_bidi_data_sg;
0528     unsigned int        t_bidi_data_nents;
0529 
0530     /* Used for lun->lun_ref counting */
0531     int         lun_ref_active;
0532 
0533     struct list_head    state_list;
0534 
0535     /* backend private data */
0536     void            *priv;
0537 
0538     /* DIF related members */
0539     enum target_prot_op prot_op;
0540     enum target_prot_type   prot_type;
0541     u8          prot_checks;
0542     bool            prot_pto;
0543     u32         prot_length;
0544     u32         reftag_seed;
0545     struct scatterlist  *t_prot_sg;
0546     unsigned int        t_prot_nents;
0547     sense_reason_t      pi_err;
0548     u64         sense_info;
0549     /*
0550      * CPU LIO will execute the cmd on. Defaults to the CPU the cmd is
0551      * initialized on. Drivers can override.
0552      */
0553     int         cpuid;
0554 };
0555 
0556 struct se_ua {
0557     u8          ua_asc;
0558     u8          ua_ascq;
0559     struct list_head    ua_nacl_list;
0560 };
0561 
0562 struct se_node_acl {
0563     char            initiatorname[TRANSPORT_IQN_LEN];
0564     /* Used to signal demo mode created ACL, disabled by default */
0565     bool            dynamic_node_acl;
0566     bool            dynamic_stop;
0567     u32         queue_depth;
0568     u32         acl_index;
0569     enum target_prot_type   saved_prot_type;
0570 #define MAX_ACL_TAG_SIZE 64
0571     char            acl_tag[MAX_ACL_TAG_SIZE];
0572     /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
0573     atomic_t        acl_pr_ref_count;
0574     struct hlist_head   lun_entry_hlist;
0575     struct se_session   *nacl_sess;
0576     struct se_portal_group *se_tpg;
0577     struct mutex        lun_entry_mutex;
0578     spinlock_t      nacl_sess_lock;
0579     struct config_group acl_group;
0580     struct config_group acl_attrib_group;
0581     struct config_group acl_auth_group;
0582     struct config_group acl_param_group;
0583     struct config_group acl_fabric_stat_group;
0584     struct list_head    acl_list;
0585     struct list_head    acl_sess_list;
0586     struct completion   acl_free_comp;
0587     struct kref     acl_kref;
0588 };
0589 
0590 static inline struct se_node_acl *acl_to_nacl(struct config_item *item)
0591 {
0592     return container_of(to_config_group(item), struct se_node_acl,
0593             acl_group);
0594 }
0595 
0596 static inline struct se_node_acl *attrib_to_nacl(struct config_item *item)
0597 {
0598     return container_of(to_config_group(item), struct se_node_acl,
0599             acl_attrib_group);
0600 }
0601 
0602 static inline struct se_node_acl *auth_to_nacl(struct config_item *item)
0603 {
0604     return container_of(to_config_group(item), struct se_node_acl,
0605             acl_auth_group);
0606 }
0607 
0608 static inline struct se_node_acl *param_to_nacl(struct config_item *item)
0609 {
0610     return container_of(to_config_group(item), struct se_node_acl,
0611             acl_param_group);
0612 }
0613 
0614 static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item)
0615 {
0616     return container_of(to_config_group(item), struct se_node_acl,
0617             acl_fabric_stat_group);
0618 }
0619 
0620 struct se_session {
0621     atomic_t        stopped;
0622     u64         sess_bin_isid;
0623     enum target_prot_op sup_prot_ops;
0624     enum target_prot_type   sess_prot_type;
0625     struct se_node_acl  *se_node_acl;
0626     struct se_portal_group *se_tpg;
0627     void            *fabric_sess_ptr;
0628     struct percpu_ref   cmd_count;
0629     struct list_head    sess_list;
0630     struct list_head    sess_acl_list;
0631     spinlock_t      sess_cmd_lock;
0632     wait_queue_head_t   cmd_count_wq;
0633     struct completion   stop_done;
0634     void            *sess_cmd_map;
0635     struct sbitmap_queue    sess_tag_pool;
0636 };
0637 
0638 struct se_device;
0639 struct se_transform_info;
0640 struct scatterlist;
0641 
0642 struct se_ml_stat_grps {
0643     struct config_group stat_group;
0644     struct config_group scsi_auth_intr_group;
0645     struct config_group scsi_att_intr_port_group;
0646 };
0647 
0648 struct se_lun_acl {
0649     u64         mapped_lun;
0650     struct se_node_acl  *se_lun_nacl;
0651     struct se_lun       *se_lun;
0652     struct config_group se_lun_group;
0653     struct se_ml_stat_grps  ml_stat_grps;
0654 };
0655 
0656 struct se_dev_entry {
0657     u64         mapped_lun;
0658     u64         pr_res_key;
0659     u64         creation_time;
0660     bool            lun_access_ro;
0661     u32         attach_count;
0662     atomic_long_t       total_cmds;
0663     atomic_long_t       read_bytes;
0664     atomic_long_t       write_bytes;
0665     /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
0666     struct kref     pr_kref;
0667     struct completion   pr_comp;
0668     struct se_lun_acl   *se_lun_acl;
0669     spinlock_t      ua_lock;
0670     struct se_lun       *se_lun;
0671 #define DEF_PR_REG_ACTIVE       1
0672     unsigned long       deve_flags;
0673     struct list_head    alua_port_list;
0674     struct list_head    lun_link;
0675     struct list_head    ua_list;
0676     struct hlist_node   link;
0677     struct rcu_head     rcu_head;
0678 };
0679 
0680 struct se_dev_attrib {
0681     bool        emulate_model_alias;
0682     bool        emulate_dpo;        /* deprecated */
0683     bool        emulate_fua_write;
0684     bool        emulate_fua_read;   /* deprecated */
0685     bool        emulate_write_cache;
0686     enum target_ua_intlck_ctrl emulate_ua_intlck_ctrl;
0687     bool        emulate_tas;
0688     bool        emulate_tpu;
0689     bool        emulate_tpws;
0690     bool        emulate_caw;
0691     bool        emulate_3pc;
0692     bool        emulate_pr;
0693     enum target_prot_type pi_prot_type;
0694     enum target_prot_type hw_pi_prot_type;
0695     bool        pi_prot_verify;
0696     bool        enforce_pr_isids;
0697     bool        force_pr_aptpl;
0698     bool        is_nonrot;
0699     bool        emulate_rest_reord;
0700     bool        unmap_zeroes_data;
0701     u32     hw_block_size;
0702     u32     block_size;
0703     u32     hw_max_sectors;
0704     u32     optimal_sectors;
0705     u32     hw_queue_depth;
0706     u32     queue_depth;
0707     u32     max_unmap_lba_count;
0708     u32     max_unmap_block_desc_count;
0709     u32     unmap_granularity;
0710     u32     unmap_granularity_alignment;
0711     u32     max_write_same_len;
0712     u32     max_bytes_per_io;
0713     struct se_device *da_dev;
0714     struct config_group da_group;
0715 };
0716 
0717 struct se_port_stat_grps {
0718     struct config_group stat_group;
0719     struct config_group scsi_port_group;
0720     struct config_group scsi_tgt_port_group;
0721     struct config_group scsi_transport_group;
0722 };
0723 
0724 struct scsi_port_stats {
0725     atomic_long_t   cmd_pdus;
0726     atomic_long_t   tx_data_octets;
0727     atomic_long_t   rx_data_octets;
0728 };
0729 
0730 struct se_lun {
0731     u64         unpacked_lun;
0732     bool            lun_shutdown;
0733     bool            lun_access_ro;
0734     u32         lun_index;
0735 
0736     /* RELATIVE TARGET PORT IDENTIFER */
0737     u16         lun_rtpi;
0738     atomic_t        lun_acl_count;
0739     struct se_device __rcu  *lun_se_dev;
0740 
0741     struct list_head    lun_deve_list;
0742     spinlock_t      lun_deve_lock;
0743 
0744     /* ALUA state */
0745     int         lun_tg_pt_secondary_stat;
0746     int         lun_tg_pt_secondary_write_md;
0747     atomic_t        lun_tg_pt_secondary_offline;
0748     struct mutex        lun_tg_pt_md_mutex;
0749 
0750     /* ALUA target port group linkage */
0751     struct list_head    lun_tg_pt_gp_link;
0752     struct t10_alua_tg_pt_gp __rcu *lun_tg_pt_gp;
0753     spinlock_t      lun_tg_pt_gp_lock;
0754 
0755     struct se_portal_group  *lun_tpg;
0756     struct scsi_port_stats  lun_stats;
0757     struct config_group lun_group;
0758     struct se_port_stat_grps port_stat_grps;
0759     struct completion   lun_shutdown_comp;
0760     struct percpu_ref   lun_ref;
0761     struct list_head    lun_dev_link;
0762     struct hlist_node   link;
0763     struct rcu_head     rcu_head;
0764 };
0765 
0766 struct se_dev_stat_grps {
0767     struct config_group stat_group;
0768     struct config_group scsi_dev_group;
0769     struct config_group scsi_tgt_dev_group;
0770     struct config_group scsi_lu_group;
0771 };
0772 
0773 struct se_cmd_queue {
0774     struct llist_head   cmd_list;
0775     struct work_struct  work;
0776 };
0777 
0778 struct se_dev_plug {
0779     struct se_device    *se_dev;
0780 };
0781 
0782 struct se_device_queue {
0783     struct list_head    state_list;
0784     spinlock_t      lock;
0785     struct se_cmd_queue sq;
0786 };
0787 
0788 struct se_device {
0789     /* RELATIVE TARGET PORT IDENTIFER Counter */
0790     u16         dev_rpti_counter;
0791     /* Used for SAM Task Attribute ordering */
0792     u32         dev_cur_ordered_id;
0793     u32         dev_flags;
0794 #define DF_CONFIGURED               0x00000001
0795 #define DF_FIRMWARE_VPD_UNIT_SERIAL     0x00000002
0796 #define DF_EMULATED_VPD_UNIT_SERIAL     0x00000004
0797 #define DF_USING_UDEV_PATH          0x00000008
0798 #define DF_USING_ALIAS              0x00000010
0799 #define DF_READ_ONLY                0x00000020
0800     u8          transport_flags;
0801     /* Physical device queue depth */
0802     u32         queue_depth;
0803     /* Used for SPC-2 reservations enforce of ISIDs */
0804     u64         dev_res_bin_isid;
0805     /* Pointer to transport specific device structure */
0806     u32         dev_index;
0807     u64         creation_time;
0808     atomic_long_t       num_resets;
0809     atomic_long_t       aborts_complete;
0810     atomic_long_t       aborts_no_task;
0811     atomic_long_t       num_cmds;
0812     atomic_long_t       read_bytes;
0813     atomic_long_t       write_bytes;
0814     /* Active commands on this virtual SE device */
0815     atomic_t        non_ordered;
0816     bool            ordered_sync_in_progress;
0817     atomic_t        delayed_cmd_count;
0818     atomic_t        dev_qf_count;
0819     u32         export_count;
0820     spinlock_t      delayed_cmd_lock;
0821     spinlock_t      dev_reservation_lock;
0822     unsigned int        dev_reservation_flags;
0823 #define DRF_SPC2_RESERVATIONS           0x00000001
0824 #define DRF_SPC2_RESERVATIONS_WITH_ISID     0x00000002
0825     spinlock_t      se_port_lock;
0826     spinlock_t      se_tmr_lock;
0827     spinlock_t      qf_cmd_lock;
0828     struct semaphore    caw_sem;
0829     /* Used for legacy SPC-2 reservations */
0830     struct se_session   *reservation_holder;
0831     /* Used for ALUA Logical Unit Group membership */
0832     struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
0833     /* Used for SPC-3 Persistent Reservations */
0834     struct t10_pr_registration *dev_pr_res_holder;
0835     struct list_head    dev_sep_list;
0836     struct list_head    dev_tmr_list;
0837     struct work_struct  qf_work_queue;
0838     struct work_struct  delayed_cmd_work;
0839     struct list_head    delayed_cmd_list;
0840     struct list_head    qf_cmd_list;
0841     /* Pointer to associated SE HBA */
0842     struct se_hba       *se_hba;
0843     /* T10 Inquiry and VPD WWN Information */
0844     struct t10_wwn      t10_wwn;
0845     /* T10 Asymmetric Logical Unit Assignment for Target Ports */
0846     struct t10_alua     t10_alua;
0847     /* T10 SPC-2 + SPC-3 Reservations */
0848     struct t10_reservation  t10_pr;
0849     struct se_dev_attrib    dev_attrib;
0850     struct config_group dev_action_group;
0851     struct config_group dev_group;
0852     struct config_group dev_pr_group;
0853     struct se_dev_stat_grps dev_stat_grps;
0854 #define SE_DEV_ALIAS_LEN 512        /* must be less than PAGE_SIZE */
0855     unsigned char       dev_alias[SE_DEV_ALIAS_LEN];
0856 #define SE_UDEV_PATH_LEN 512        /* must be less than PAGE_SIZE */
0857     unsigned char       udev_path[SE_UDEV_PATH_LEN];
0858     /* Pointer to template of function pointers for transport */
0859     const struct target_backend_ops *transport;
0860     struct se_lun       xcopy_lun;
0861     /* Protection Information */
0862     int         prot_length;
0863     /* For se_lun->lun_se_dev RCU read-side critical access */
0864     u32         hba_index;
0865     struct rcu_head     rcu_head;
0866     int         queue_cnt;
0867     struct se_device_queue  *queues;
0868 };
0869 
0870 struct se_hba {
0871     u16         hba_tpgt;
0872     u32         hba_id;
0873     /* See hba_flags_table */
0874     u32         hba_flags;
0875     /* Virtual iSCSI devices attached. */
0876     u32         dev_count;
0877     u32         hba_index;
0878     /* Pointer to transport specific host structure. */
0879     void            *hba_ptr;
0880     struct list_head    hba_node;
0881     spinlock_t      device_lock;
0882     struct config_group hba_group;
0883     struct mutex        hba_access_mutex;
0884     struct target_backend   *backend;
0885 };
0886 
0887 struct se_tpg_np {
0888     struct se_portal_group *tpg_np_parent;
0889     struct config_group tpg_np_group;
0890 };
0891 
0892 static inline struct se_tpg_np *to_tpg_np(struct config_item *item)
0893 {
0894     return container_of(to_config_group(item), struct se_tpg_np,
0895             tpg_np_group);
0896 }
0897 
0898 struct se_portal_group {
0899     /*
0900      * PROTOCOL IDENTIFIER value per SPC4, 7.5.1.
0901      *
0902      * Negative values can be used by fabric drivers for internal use TPGs.
0903      */
0904     int         proto_id;
0905     bool            enabled;
0906     /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
0907     atomic_t        tpg_pr_ref_count;
0908     /* Spinlock for adding/removing ACLed Nodes */
0909     struct mutex        acl_node_mutex;
0910     /* Spinlock for adding/removing sessions */
0911     spinlock_t      session_lock;
0912     struct mutex        tpg_lun_mutex;
0913     /* linked list for initiator ACL list */
0914     struct list_head    acl_node_list;
0915     struct hlist_head   tpg_lun_hlist;
0916     struct se_lun       *tpg_virt_lun0;
0917     /* List of TCM sessions associated wth this TPG */
0918     struct list_head    tpg_sess_list;
0919     /* Pointer to $FABRIC_MOD dependent code */
0920     const struct target_core_fabric_ops *se_tpg_tfo;
0921     struct se_wwn       *se_tpg_wwn;
0922     struct config_group tpg_group;
0923     struct config_group tpg_lun_group;
0924     struct config_group tpg_np_group;
0925     struct config_group tpg_acl_group;
0926     struct config_group tpg_attrib_group;
0927     struct config_group tpg_auth_group;
0928     struct config_group tpg_param_group;
0929 };
0930 
0931 static inline struct se_portal_group *to_tpg(struct config_item *item)
0932 {
0933     return container_of(to_config_group(item), struct se_portal_group,
0934             tpg_group);
0935 }
0936 
0937 static inline struct se_portal_group *attrib_to_tpg(struct config_item *item)
0938 {
0939     return container_of(to_config_group(item), struct se_portal_group,
0940             tpg_attrib_group);
0941 }
0942 
0943 static inline struct se_portal_group *auth_to_tpg(struct config_item *item)
0944 {
0945     return container_of(to_config_group(item), struct se_portal_group,
0946             tpg_auth_group);
0947 }
0948 
0949 static inline struct se_portal_group *param_to_tpg(struct config_item *item)
0950 {
0951     return container_of(to_config_group(item), struct se_portal_group,
0952             tpg_param_group);
0953 }
0954 
0955 enum {
0956     /* Use se_cmd's cpuid for completion */
0957     SE_COMPL_AFFINITY_CPUID     = -1,
0958     /* Complete on current CPU */
0959     SE_COMPL_AFFINITY_CURR_CPU  = -2,
0960 };
0961 
0962 struct se_wwn {
0963     struct target_fabric_configfs *wwn_tf;
0964     void            *priv;
0965     struct config_group wwn_group;
0966     struct config_group fabric_stat_group;
0967     struct config_group param_group;
0968     int         cmd_compl_affinity;
0969 };
0970 
0971 static inline void atomic_inc_mb(atomic_t *v)
0972 {
0973     smp_mb__before_atomic();
0974     atomic_inc(v);
0975     smp_mb__after_atomic();
0976 }
0977 
0978 static inline void atomic_dec_mb(atomic_t *v)
0979 {
0980     smp_mb__before_atomic();
0981     atomic_dec(v);
0982     smp_mb__after_atomic();
0983 }
0984 
0985 static inline void target_free_tag(struct se_session *sess, struct se_cmd *cmd)
0986 {
0987     sbitmap_queue_clear(&sess->sess_tag_pool, cmd->map_tag, cmd->map_cpu);
0988 }
0989 
0990 #endif /* TARGET_CORE_BASE_H */