1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2c4795fb2SChristoph Hellwig #ifndef TARGET_CORE_FABRIC_H 3c4795fb2SChristoph Hellwig #define TARGET_CORE_FABRIC_H 4c4795fb2SChristoph Hellwig 58dcf07beSBart Van Assche #include <linux/configfs.h> 68dcf07beSBart Van Assche #include <linux/types.h> 78dcf07beSBart Van Assche #include <target/target_core_base.h> 88dcf07beSBart Van Assche 9c4795fb2SChristoph Hellwig struct target_core_fabric_ops { 109ac8928eSChristoph Hellwig struct module *module; 1130c7ca93SDavid Disseldorp /* 1259a206b4SDavid Disseldorp * XXX: Special case for iscsi/iSCSI... 1359a206b4SDavid Disseldorp * If non-null, fabric_alias is used for matching target/$fabric 1459a206b4SDavid Disseldorp * ConfigFS paths. If null, fabric_name is used for this (see below). 1559a206b4SDavid Disseldorp */ 1659a206b4SDavid Disseldorp const char *fabric_alias; 1759a206b4SDavid Disseldorp /* 1859a206b4SDavid Disseldorp * fabric_name is used for matching target/$fabric ConfigFS paths 1959a206b4SDavid Disseldorp * without a fabric_alias (see above). It's also used for the ALUA state 2059a206b4SDavid Disseldorp * path and is stored on disk with PR state. 2130c7ca93SDavid Disseldorp */ 2230c7ca93SDavid Disseldorp const char *fabric_name; 23144bc4c2SChristoph Hellwig size_t node_acl_size; 248f9b5654SNicholas Bellinger /* 258f9b5654SNicholas Bellinger * Limits number of scatterlist entries per SCF_SCSI_DATA_CDB payload. 268f9b5654SNicholas Bellinger * Setting this value tells target-core to enforce this limit, and 278f9b5654SNicholas Bellinger * report as INQUIRY EVPD=b0 MAXIMUM TRANSFER LENGTH. 288f9b5654SNicholas Bellinger * 298f9b5654SNicholas Bellinger * target-core will currently reset se_cmd->data_length to this 308f9b5654SNicholas Bellinger * maximum size, and set UNDERFLOW residual count if length exceeds 318f9b5654SNicholas Bellinger * this limit. 328f9b5654SNicholas Bellinger * 338f9b5654SNicholas Bellinger * XXX: Not all initiator hosts honor this block-limit EVPD 348f9b5654SNicholas Bellinger * XXX: Currently assumes single PAGE_SIZE per scatterlist entry 358f9b5654SNicholas Bellinger */ 368f9b5654SNicholas Bellinger u32 max_data_sg_nents; 37c4795fb2SChristoph Hellwig char *(*tpg_get_wwn)(struct se_portal_group *); 38c4795fb2SChristoph Hellwig u16 (*tpg_get_tag)(struct se_portal_group *); 39c4795fb2SChristoph Hellwig u32 (*tpg_get_default_depth)(struct se_portal_group *); 40c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode)(struct se_portal_group *); 41c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_cache)(struct se_portal_group *); 42c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *); 43c4795fb2SChristoph Hellwig int (*tpg_check_prod_mode_write_protect)(struct se_portal_group *); 44c4795fb2SChristoph Hellwig /* 45c4795fb2SChristoph Hellwig * Optionally used by fabrics to allow demo-mode login, but not 46c4795fb2SChristoph Hellwig * expose any TPG LUNs, and return 'not connected' in standard 47c4795fb2SChristoph Hellwig * inquiry response 48c4795fb2SChristoph Hellwig */ 49c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_login_only)(struct se_portal_group *); 5038b57f82SNicholas Bellinger /* 5138b57f82SNicholas Bellinger * Optionally used as a configfs tunable to determine when 5238b57f82SNicholas Bellinger * target-core should signal the PROTECT=1 feature bit for 5338b57f82SNicholas Bellinger * backends that don't support T10-PI, so that either fabric 5438b57f82SNicholas Bellinger * HW offload or target-core emulation performs the associated 5538b57f82SNicholas Bellinger * WRITE_STRIP and READ_INSERT operations. 5638b57f82SNicholas Bellinger */ 5738b57f82SNicholas Bellinger int (*tpg_check_prot_fabric_only)(struct se_portal_group *); 58c4795fb2SChristoph Hellwig u32 (*tpg_get_inst_index)(struct se_portal_group *); 59c4795fb2SChristoph Hellwig /* 60c4795fb2SChristoph Hellwig * Optional to release struct se_cmd and fabric dependent allocated 61b1a2ecdaSBart Van Assche * I/O descriptor after command execution has finished. 62c4795fb2SChristoph Hellwig * 63c4795fb2SChristoph Hellwig * Returning 1 will signal a descriptor has been released. 64c4795fb2SChristoph Hellwig * Returning 0 will signal a descriptor has not been released. 65c4795fb2SChristoph Hellwig */ 66c4795fb2SChristoph Hellwig int (*check_stop_free)(struct se_cmd *); 67c4795fb2SChristoph Hellwig void (*release_cmd)(struct se_cmd *); 68c4795fb2SChristoph Hellwig void (*close_session)(struct se_session *); 69c4795fb2SChristoph Hellwig u32 (*sess_get_index)(struct se_session *); 70c4795fb2SChristoph Hellwig /* 71c4795fb2SChristoph Hellwig * Used only for SCSI fabrics that contain multi-value TransportIDs 72c4795fb2SChristoph Hellwig * (like iSCSI). All other SCSI fabrics should set this to NULL. 73c4795fb2SChristoph Hellwig */ 74c4795fb2SChristoph Hellwig u32 (*sess_get_initiator_sid)(struct se_session *, 75c4795fb2SChristoph Hellwig unsigned char *, u32); 76c4795fb2SChristoph Hellwig int (*write_pending)(struct se_cmd *); 77c4795fb2SChristoph Hellwig void (*set_default_node_attributes)(struct se_node_acl *); 78c4795fb2SChristoph Hellwig int (*get_cmd_state)(struct se_cmd *); 79c4795fb2SChristoph Hellwig int (*queue_data_in)(struct se_cmd *); 80c4795fb2SChristoph Hellwig int (*queue_status)(struct se_cmd *); 81b79fafacSJoern Engel void (*queue_tm_rsp)(struct se_cmd *); 82131e6abcSNicholas Bellinger void (*aborted_task)(struct se_cmd *); 83c4795fb2SChristoph Hellwig /* 84c4795fb2SChristoph Hellwig * fabric module calls for target_core_fabric_configfs.c 85c4795fb2SChristoph Hellwig */ 86c4795fb2SChristoph Hellwig struct se_wwn *(*fabric_make_wwn)(struct target_fabric_configfs *, 87c4795fb2SChristoph Hellwig struct config_group *, const char *); 88c4795fb2SChristoph Hellwig void (*fabric_drop_wwn)(struct se_wwn *); 89839559e1SChristoph Hellwig void (*add_wwn_groups)(struct se_wwn *); 90c4795fb2SChristoph Hellwig struct se_portal_group *(*fabric_make_tpg)(struct se_wwn *, 91aa090eabSBart Van Assche const char *); 92*80ed33c8SDmitry Bogdanov int (*fabric_enable_tpg)(struct se_portal_group *se_tpg, bool enable); 93c4795fb2SChristoph Hellwig void (*fabric_drop_tpg)(struct se_portal_group *); 94c4795fb2SChristoph Hellwig int (*fabric_post_link)(struct se_portal_group *, 95c4795fb2SChristoph Hellwig struct se_lun *); 96c4795fb2SChristoph Hellwig void (*fabric_pre_unlink)(struct se_portal_group *, 97c4795fb2SChristoph Hellwig struct se_lun *); 98c4795fb2SChristoph Hellwig struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *, 99c4795fb2SChristoph Hellwig struct config_group *, const char *); 100c4795fb2SChristoph Hellwig void (*fabric_drop_np)(struct se_tpg_np *); 101c7d6a803SChristoph Hellwig int (*fabric_init_nodeacl)(struct se_node_acl *, const char *); 1029ac8928eSChristoph Hellwig 1039ac8928eSChristoph Hellwig struct configfs_attribute **tfc_discovery_attrs; 1049ac8928eSChristoph Hellwig struct configfs_attribute **tfc_wwn_attrs; 1059ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_base_attrs; 1069ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_np_base_attrs; 1079ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_attrib_attrs; 1089ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_auth_attrs; 1099ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_param_attrs; 1109ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_base_attrs; 1119ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_attrib_attrs; 1129ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_auth_attrs; 1139ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_param_attrs; 114fbbd4923SBart Van Assche 115fbbd4923SBart Van Assche /* 116fbbd4923SBart Van Assche * Set this member variable to true if the SCSI transport protocol 117fbbd4923SBart Van Assche * (e.g. iSCSI) requires that the Data-Out buffer is transferred in 118fbbd4923SBart Van Assche * its entirety before a command is aborted. 119fbbd4923SBart Van Assche */ 120fbbd4923SBart Van Assche bool write_pending_must_be_called; 121c4795fb2SChristoph Hellwig }; 122c4795fb2SChristoph Hellwig 1239ac8928eSChristoph Hellwig int target_register_template(const struct target_core_fabric_ops *fo); 1249ac8928eSChristoph Hellwig void target_unregister_template(const struct target_core_fabric_ops *fo); 1259ac8928eSChristoph Hellwig 126d588cf8fSChristoph Hellwig int target_depend_item(struct config_item *item); 127d588cf8fSChristoph Hellwig void target_undepend_item(struct config_item *item); 128d588cf8fSChristoph Hellwig 129fa834287SMike Christie struct se_session *target_setup_session(struct se_portal_group *, 1307861728dSNicholas Bellinger unsigned int, unsigned int, enum target_prot_op prot_op, 1317861728dSNicholas Bellinger const char *, void *, 1327861728dSNicholas Bellinger int (*callback)(struct se_portal_group *, 1337861728dSNicholas Bellinger struct se_session *, void *)); 134fb7c70f2SMike Christie void target_remove_session(struct se_session *); 1357861728dSNicholas Bellinger 136ad669505SBart Van Assche int transport_init_session(struct se_session *se_sess); 137317f8971SBart Van Assche struct se_session *transport_alloc_session(enum target_prot_op); 138c0add7fdSNicholas Bellinger int transport_alloc_session_tags(struct se_session *, unsigned int, 139c0add7fdSNicholas Bellinger unsigned int); 140c4795fb2SChristoph Hellwig void __transport_register_session(struct se_portal_group *, 141c4795fb2SChristoph Hellwig struct se_node_acl *, struct se_session *, void *); 142c4795fb2SChristoph Hellwig void transport_register_session(struct se_portal_group *, 143c4795fb2SChristoph Hellwig struct se_node_acl *, struct se_session *, void *); 144f8e471f9SNicholas Bellinger ssize_t target_show_dynamic_sessions(struct se_portal_group *, char *); 145c4795fb2SChristoph Hellwig void transport_free_session(struct se_session *); 146fae43461SBart Van Assche void target_spc2_release(struct se_node_acl *nacl); 147afb999ffSNicholas Bellinger void target_put_nacl(struct se_node_acl *); 148c4795fb2SChristoph Hellwig void transport_deregister_session_configfs(struct se_session *); 149c4795fb2SChristoph Hellwig void transport_deregister_session(struct se_session *); 150c4795fb2SChristoph Hellwig 151c4795fb2SChristoph Hellwig 152a78b7136SMike Christie void __target_init_cmd(struct se_cmd *, 1539ac8928eSChristoph Hellwig const struct target_core_fabric_ops *, 154a36840d8SSudhakar Panneerselvam struct se_session *, u32, int, int, unsigned char *, u64); 155750a1d93SMike Christie int target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, 156750a1d93SMike Christie unsigned char *sense, u64 unpacked_lun, u32 data_length, 157750a1d93SMike Christie int task_attr, int data_dir, int flags); 158750a1d93SMike Christie int target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb, 159750a1d93SMike Christie struct scatterlist *sgl, u32 sgl_count, 160750a1d93SMike Christie struct scatterlist *sgl_bidi, u32 sgl_bidi_count, 16108694199SMike Christie struct scatterlist *sgl_prot, u32 sgl_prot_count, gfp_t gfp); 162750a1d93SMike Christie void target_submit(struct se_cmd *se_cmd); 163a36840d8SSudhakar Panneerselvam sense_reason_t transport_lookup_cmd_lun(struct se_cmd *); 16408694199SMike Christie sense_reason_t target_cmd_init_cdb(struct se_cmd *se_cmd, unsigned char *cdb, 16508694199SMike Christie gfp_t gfp); 166987db587SSudhakar Panneerselvam sense_reason_t target_cmd_parse_cdb(struct se_cmd *); 1670fa50a8bSMike Christie void target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, 168f2d30680SHannes Reinecke unsigned char *, u64, u32, int, int, int); 169eb44ce8cSMike Christie void target_queue_submission(struct se_cmd *se_cmd); 170eb44ce8cSMike Christie 171c7042caeSNicholas Bellinger int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, 172f2d30680SHannes Reinecke unsigned char *sense, u64 unpacked_lun, 173c0974f89SNicholas Bellinger void *fabric_tmr_ptr, unsigned char tm_type, 1745261d86cSBart Van Assche gfp_t, u64, int); 175c4795fb2SChristoph Hellwig int transport_handle_cdb_direct(struct se_cmd *); 176de103c93SChristoph Hellwig sense_reason_t transport_generic_new_cmd(struct se_cmd *); 177c4795fb2SChristoph Hellwig 1782c9fa49eSBart Van Assche void target_put_cmd_and_wait(struct se_cmd *cmd); 17970baf0abSChristoph Hellwig void target_execute_cmd(struct se_cmd *cmd); 180c4795fb2SChristoph Hellwig 181d5ddad41SNicholas Bellinger int transport_generic_free_cmd(struct se_cmd *, int); 182c4795fb2SChristoph Hellwig 183c4795fb2SChristoph Hellwig bool transport_wait_for_tasks(struct se_cmd *); 184de103c93SChristoph Hellwig int transport_send_check_condition_and_sense(struct se_cmd *, 185de103c93SChristoph Hellwig sense_reason_t, int); 18694ebb471SBart Van Assche int target_send_busy(struct se_cmd *cmd); 187afc16604SBart Van Assche int target_get_sess_cmd(struct se_cmd *, bool); 188afc16604SBart Van Assche int target_put_sess_cmd(struct se_cmd *); 1896f55b06fSMike Christie void target_stop_session(struct se_session *se_sess); 190be646c2dSJoern Engel void target_wait_for_sess_cmds(struct se_session *); 191c00e6220SBart Van Assche void target_show_cmd(const char *pfx, struct se_cmd *cmd); 192c4795fb2SChristoph Hellwig 193c4795fb2SChristoph Hellwig int core_alua_check_nonop_delay(struct se_cmd *); 194c4795fb2SChristoph Hellwig 195c8e31f26SAndy Grover int core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t); 196c4795fb2SChristoph Hellwig void core_tmr_release_req(struct se_tmr_req *); 197c4795fb2SChristoph Hellwig int transport_generic_handle_tmr(struct se_cmd *); 198de103c93SChristoph Hellwig void transport_generic_request_failure(struct se_cmd *, sense_reason_t); 199a36840d8SSudhakar Panneerselvam int transport_lookup_tmr_lun(struct se_cmd *); 200e986a35aSHannes Reinecke void core_allocate_nexus_loss_ua(struct se_node_acl *acl); 201c4795fb2SChristoph Hellwig 202b3fde035SThomas Glanzmann struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg, 203b3fde035SThomas Glanzmann unsigned char *); 20421aaa23bSNicholas Bellinger bool target_tpg_has_node_acl(struct se_portal_group *tpg, 20521aaa23bSNicholas Bellinger const char *); 206c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *, 207c4795fb2SChristoph Hellwig unsigned char *); 208d36ad77fSNicholas Bellinger int core_tpg_set_initiator_node_queue_depth(struct se_node_acl *, u32); 20979e62fc3SAndy Grover int core_tpg_set_initiator_node_tag(struct se_portal_group *, 21079e62fc3SAndy Grover struct se_node_acl *, const char *); 211bc0c94b1SNicholas Bellinger int core_tpg_register(struct se_wwn *, struct se_portal_group *, int); 212c4795fb2SChristoph Hellwig int core_tpg_deregister(struct se_portal_group *); 213c4795fb2SChristoph Hellwig 214e64aa657SChristoph Hellwig int target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, 215e64aa657SChristoph Hellwig u32 length, bool zero_page, bool chainable); 216e64aa657SChristoph Hellwig void target_free_sgl(struct scatterlist *sgl, int nents); 217e64aa657SChristoph Hellwig 218b3faa2e8SNicholas Bellinger /* 219b3faa2e8SNicholas Bellinger * The LIO target core uses DMA_TO_DEVICE to mean that data is going 220b3faa2e8SNicholas Bellinger * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean 221b3faa2e8SNicholas Bellinger * that data is coming from the target (eg handling a READ). However, 222b3faa2e8SNicholas Bellinger * this is just the opposite of what we have to tell the DMA mapping 223b3faa2e8SNicholas Bellinger * layer -- eg when handling a READ, the HBA will have to DMA the data 224b3faa2e8SNicholas Bellinger * out of memory so it can send it to the initiator, which means we 225b3faa2e8SNicholas Bellinger * need to use DMA_TO_DEVICE when we map the data. 226b3faa2e8SNicholas Bellinger */ 227b3faa2e8SNicholas Bellinger static inline enum dma_data_direction 228b3faa2e8SNicholas Bellinger target_reverse_dma_direction(struct se_cmd *se_cmd) 229b3faa2e8SNicholas Bellinger { 230b3faa2e8SNicholas Bellinger if (se_cmd->se_cmd_flags & SCF_BIDI) 231b3faa2e8SNicholas Bellinger return DMA_BIDIRECTIONAL; 232b3faa2e8SNicholas Bellinger 233b3faa2e8SNicholas Bellinger switch (se_cmd->data_direction) { 234b3faa2e8SNicholas Bellinger case DMA_TO_DEVICE: 235b3faa2e8SNicholas Bellinger return DMA_FROM_DEVICE; 236b3faa2e8SNicholas Bellinger case DMA_FROM_DEVICE: 237b3faa2e8SNicholas Bellinger return DMA_TO_DEVICE; 238b3faa2e8SNicholas Bellinger case DMA_NONE: 239b3faa2e8SNicholas Bellinger default: 240b3faa2e8SNicholas Bellinger return DMA_NONE; 241b3faa2e8SNicholas Bellinger } 242b3faa2e8SNicholas Bellinger } 243b3faa2e8SNicholas Bellinger 244c4795fb2SChristoph Hellwig #endif /* TARGET_CORE_FABRICH */ 245