1c4795fb2SChristoph Hellwig #ifndef TARGET_CORE_FABRIC_H 2c4795fb2SChristoph Hellwig #define TARGET_CORE_FABRIC_H 3c4795fb2SChristoph Hellwig 4c4795fb2SChristoph Hellwig struct target_core_fabric_ops { 59ac8928eSChristoph Hellwig struct module *module; 69ac8928eSChristoph Hellwig const char *name; 7144bc4c2SChristoph Hellwig size_t node_acl_size; 8c4795fb2SChristoph Hellwig char *(*get_fabric_name)(void); 9c4795fb2SChristoph Hellwig char *(*tpg_get_wwn)(struct se_portal_group *); 10c4795fb2SChristoph Hellwig u16 (*tpg_get_tag)(struct se_portal_group *); 11c4795fb2SChristoph Hellwig u32 (*tpg_get_default_depth)(struct se_portal_group *); 12c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode)(struct se_portal_group *); 13c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_cache)(struct se_portal_group *); 14c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *); 15c4795fb2SChristoph Hellwig int (*tpg_check_prod_mode_write_protect)(struct se_portal_group *); 16c4795fb2SChristoph Hellwig /* 17c4795fb2SChristoph Hellwig * Optionally used by fabrics to allow demo-mode login, but not 18c4795fb2SChristoph Hellwig * expose any TPG LUNs, and return 'not connected' in standard 19c4795fb2SChristoph Hellwig * inquiry response 20c4795fb2SChristoph Hellwig */ 21c4795fb2SChristoph Hellwig int (*tpg_check_demo_mode_login_only)(struct se_portal_group *); 2238b57f82SNicholas Bellinger /* 2338b57f82SNicholas Bellinger * Optionally used as a configfs tunable to determine when 2438b57f82SNicholas Bellinger * target-core should signal the PROTECT=1 feature bit for 2538b57f82SNicholas Bellinger * backends that don't support T10-PI, so that either fabric 2638b57f82SNicholas Bellinger * HW offload or target-core emulation performs the associated 2738b57f82SNicholas Bellinger * WRITE_STRIP and READ_INSERT operations. 2838b57f82SNicholas Bellinger */ 2938b57f82SNicholas Bellinger int (*tpg_check_prot_fabric_only)(struct se_portal_group *); 30c4795fb2SChristoph Hellwig u32 (*tpg_get_inst_index)(struct se_portal_group *); 31c4795fb2SChristoph Hellwig /* 32c4795fb2SChristoph Hellwig * Optional to release struct se_cmd and fabric dependent allocated 33c4795fb2SChristoph Hellwig * I/O descriptor in transport_cmd_check_stop(). 34c4795fb2SChristoph Hellwig * 35c4795fb2SChristoph Hellwig * Returning 1 will signal a descriptor has been released. 36c4795fb2SChristoph Hellwig * Returning 0 will signal a descriptor has not been released. 37c4795fb2SChristoph Hellwig */ 38c4795fb2SChristoph Hellwig int (*check_stop_free)(struct se_cmd *); 39c4795fb2SChristoph Hellwig void (*release_cmd)(struct se_cmd *); 40c4795fb2SChristoph Hellwig /* 41c4795fb2SChristoph Hellwig * Called with spin_lock_bh(struct se_portal_group->session_lock held. 42c4795fb2SChristoph Hellwig */ 43c4795fb2SChristoph Hellwig int (*shutdown_session)(struct se_session *); 44c4795fb2SChristoph Hellwig void (*close_session)(struct se_session *); 45c4795fb2SChristoph Hellwig u32 (*sess_get_index)(struct se_session *); 46c4795fb2SChristoph Hellwig /* 47c4795fb2SChristoph Hellwig * Used only for SCSI fabrics that contain multi-value TransportIDs 48c4795fb2SChristoph Hellwig * (like iSCSI). All other SCSI fabrics should set this to NULL. 49c4795fb2SChristoph Hellwig */ 50c4795fb2SChristoph Hellwig u32 (*sess_get_initiator_sid)(struct se_session *, 51c4795fb2SChristoph Hellwig unsigned char *, u32); 52c4795fb2SChristoph Hellwig int (*write_pending)(struct se_cmd *); 53c4795fb2SChristoph Hellwig int (*write_pending_status)(struct se_cmd *); 54c4795fb2SChristoph Hellwig void (*set_default_node_attributes)(struct se_node_acl *); 55c4795fb2SChristoph Hellwig int (*get_cmd_state)(struct se_cmd *); 56c4795fb2SChristoph Hellwig int (*queue_data_in)(struct se_cmd *); 57c4795fb2SChristoph Hellwig int (*queue_status)(struct se_cmd *); 58b79fafacSJoern Engel void (*queue_tm_rsp)(struct se_cmd *); 59131e6abcSNicholas Bellinger void (*aborted_task)(struct se_cmd *); 60c4795fb2SChristoph Hellwig /* 61c4795fb2SChristoph Hellwig * fabric module calls for target_core_fabric_configfs.c 62c4795fb2SChristoph Hellwig */ 63c4795fb2SChristoph Hellwig struct se_wwn *(*fabric_make_wwn)(struct target_fabric_configfs *, 64c4795fb2SChristoph Hellwig struct config_group *, const char *); 65c4795fb2SChristoph Hellwig void (*fabric_drop_wwn)(struct se_wwn *); 66c4795fb2SChristoph Hellwig struct se_portal_group *(*fabric_make_tpg)(struct se_wwn *, 67c4795fb2SChristoph Hellwig struct config_group *, const char *); 68c4795fb2SChristoph Hellwig void (*fabric_drop_tpg)(struct se_portal_group *); 69c4795fb2SChristoph Hellwig int (*fabric_post_link)(struct se_portal_group *, 70c4795fb2SChristoph Hellwig struct se_lun *); 71c4795fb2SChristoph Hellwig void (*fabric_pre_unlink)(struct se_portal_group *, 72c4795fb2SChristoph Hellwig struct se_lun *); 73c4795fb2SChristoph Hellwig struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *, 74c4795fb2SChristoph Hellwig struct config_group *, const char *); 75c4795fb2SChristoph Hellwig void (*fabric_drop_np)(struct se_tpg_np *); 76c7d6a803SChristoph Hellwig int (*fabric_init_nodeacl)(struct se_node_acl *, const char *); 77c7d6a803SChristoph Hellwig void (*fabric_cleanup_nodeacl)(struct se_node_acl *); 789ac8928eSChristoph Hellwig 799ac8928eSChristoph Hellwig struct configfs_attribute **tfc_discovery_attrs; 809ac8928eSChristoph Hellwig struct configfs_attribute **tfc_wwn_attrs; 819ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_base_attrs; 829ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_np_base_attrs; 839ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_attrib_attrs; 849ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_auth_attrs; 859ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_param_attrs; 869ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_base_attrs; 879ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_attrib_attrs; 889ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_auth_attrs; 899ac8928eSChristoph Hellwig struct configfs_attribute **tfc_tpg_nacl_param_attrs; 90c4795fb2SChristoph Hellwig }; 91c4795fb2SChristoph Hellwig 929ac8928eSChristoph Hellwig int target_register_template(const struct target_core_fabric_ops *fo); 939ac8928eSChristoph Hellwig void target_unregister_template(const struct target_core_fabric_ops *fo); 949ac8928eSChristoph Hellwig 95d588cf8fSChristoph Hellwig int target_depend_item(struct config_item *item); 96d588cf8fSChristoph Hellwig void target_undepend_item(struct config_item *item); 97d588cf8fSChristoph Hellwig 98e70beee7SNicholas Bellinger struct se_session *transport_init_session(enum target_prot_op); 99c0add7fdSNicholas Bellinger int transport_alloc_session_tags(struct se_session *, unsigned int, 100c0add7fdSNicholas Bellinger unsigned int); 101e70beee7SNicholas Bellinger struct se_session *transport_init_session_tags(unsigned int, unsigned int, 102e70beee7SNicholas Bellinger enum target_prot_op); 103c4795fb2SChristoph Hellwig void __transport_register_session(struct se_portal_group *, 104c4795fb2SChristoph Hellwig struct se_node_acl *, struct se_session *, void *); 105c4795fb2SChristoph Hellwig void transport_register_session(struct se_portal_group *, 106c4795fb2SChristoph Hellwig struct se_node_acl *, struct se_session *, void *); 10741ac82b6SNicholas Bellinger void target_get_session(struct se_session *); 10833933a0eSJörn Engel void target_put_session(struct se_session *); 109f8e471f9SNicholas Bellinger ssize_t target_show_dynamic_sessions(struct se_portal_group *, char *); 110c4795fb2SChristoph Hellwig void transport_free_session(struct se_session *); 111afb999ffSNicholas Bellinger void target_put_nacl(struct se_node_acl *); 112c4795fb2SChristoph Hellwig void transport_deregister_session_configfs(struct se_session *); 113c4795fb2SChristoph Hellwig void transport_deregister_session(struct se_session *); 114c4795fb2SChristoph Hellwig 115c4795fb2SChristoph Hellwig 1169ac8928eSChristoph Hellwig void transport_init_se_cmd(struct se_cmd *, 1179ac8928eSChristoph Hellwig const struct target_core_fabric_ops *, 118c4795fb2SChristoph Hellwig struct se_session *, u32, int, int, unsigned char *); 119*f2d30680SHannes Reinecke sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64); 120de103c93SChristoph Hellwig sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); 121a026757fSNicholas Bellinger int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, 122*f2d30680SHannes Reinecke unsigned char *, unsigned char *, u64, u32, int, int, int, 123def2b339SNicholas Bellinger struct scatterlist *, u32, struct scatterlist *, u32, 124def2b339SNicholas Bellinger struct scatterlist *, u32); 125d6dfc868SRoland Dreier int target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, 126*f2d30680SHannes Reinecke unsigned char *, u64, u32, int, int, int); 127c7042caeSNicholas Bellinger int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, 128*f2d30680SHannes Reinecke unsigned char *sense, u64 unpacked_lun, 129c0974f89SNicholas Bellinger void *fabric_tmr_ptr, unsigned char tm_type, 130c0974f89SNicholas Bellinger gfp_t, unsigned int, int); 131c4795fb2SChristoph Hellwig int transport_handle_cdb_direct(struct se_cmd *); 132de103c93SChristoph Hellwig sense_reason_t transport_generic_new_cmd(struct se_cmd *); 133c4795fb2SChristoph Hellwig 13470baf0abSChristoph Hellwig void target_execute_cmd(struct se_cmd *cmd); 135c4795fb2SChristoph Hellwig 136d5ddad41SNicholas Bellinger int transport_generic_free_cmd(struct se_cmd *, int); 137c4795fb2SChristoph Hellwig 138c4795fb2SChristoph Hellwig bool transport_wait_for_tasks(struct se_cmd *); 139c4795fb2SChristoph Hellwig int transport_check_aborted_status(struct se_cmd *, int); 140de103c93SChristoph Hellwig int transport_send_check_condition_and_sense(struct se_cmd *, 141de103c93SChristoph Hellwig sense_reason_t, int); 142afc16604SBart Van Assche int target_get_sess_cmd(struct se_cmd *, bool); 143afc16604SBart Van Assche int target_put_sess_cmd(struct se_cmd *); 1441c7b13feSRoland Dreier void target_sess_cmd_list_set_waiting(struct se_session *); 145be646c2dSJoern Engel void target_wait_for_sess_cmds(struct se_session *); 146c4795fb2SChristoph Hellwig 147c4795fb2SChristoph Hellwig int core_alua_check_nonop_delay(struct se_cmd *); 148c4795fb2SChristoph Hellwig 149c8e31f26SAndy Grover int core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t); 150c4795fb2SChristoph Hellwig void core_tmr_release_req(struct se_tmr_req *); 151c4795fb2SChristoph Hellwig int transport_generic_handle_tmr(struct se_cmd *); 152de103c93SChristoph Hellwig void transport_generic_request_failure(struct se_cmd *, sense_reason_t); 15376dde50eSNicholas Bellinger void __target_execute_cmd(struct se_cmd *); 154*f2d30680SHannes Reinecke int transport_lookup_tmr_lun(struct se_cmd *, u64); 155c4795fb2SChristoph Hellwig 156b3fde035SThomas Glanzmann struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg, 157b3fde035SThomas Glanzmann unsigned char *); 158c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *, 159c4795fb2SChristoph Hellwig unsigned char *); 160c4795fb2SChristoph Hellwig int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *, 161c4795fb2SChristoph Hellwig unsigned char *, u32, int); 16279e62fc3SAndy Grover int core_tpg_set_initiator_node_tag(struct se_portal_group *, 16379e62fc3SAndy Grover struct se_node_acl *, const char *); 164bc0c94b1SNicholas Bellinger int core_tpg_register(struct se_wwn *, struct se_portal_group *, int); 165c4795fb2SChristoph Hellwig int core_tpg_deregister(struct se_portal_group *); 166c4795fb2SChristoph Hellwig 167b3faa2e8SNicholas Bellinger /* 168b3faa2e8SNicholas Bellinger * The LIO target core uses DMA_TO_DEVICE to mean that data is going 169b3faa2e8SNicholas Bellinger * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean 170b3faa2e8SNicholas Bellinger * that data is coming from the target (eg handling a READ). However, 171b3faa2e8SNicholas Bellinger * this is just the opposite of what we have to tell the DMA mapping 172b3faa2e8SNicholas Bellinger * layer -- eg when handling a READ, the HBA will have to DMA the data 173b3faa2e8SNicholas Bellinger * out of memory so it can send it to the initiator, which means we 174b3faa2e8SNicholas Bellinger * need to use DMA_TO_DEVICE when we map the data. 175b3faa2e8SNicholas Bellinger */ 176b3faa2e8SNicholas Bellinger static inline enum dma_data_direction 177b3faa2e8SNicholas Bellinger target_reverse_dma_direction(struct se_cmd *se_cmd) 178b3faa2e8SNicholas Bellinger { 179b3faa2e8SNicholas Bellinger if (se_cmd->se_cmd_flags & SCF_BIDI) 180b3faa2e8SNicholas Bellinger return DMA_BIDIRECTIONAL; 181b3faa2e8SNicholas Bellinger 182b3faa2e8SNicholas Bellinger switch (se_cmd->data_direction) { 183b3faa2e8SNicholas Bellinger case DMA_TO_DEVICE: 184b3faa2e8SNicholas Bellinger return DMA_FROM_DEVICE; 185b3faa2e8SNicholas Bellinger case DMA_FROM_DEVICE: 186b3faa2e8SNicholas Bellinger return DMA_TO_DEVICE; 187b3faa2e8SNicholas Bellinger case DMA_NONE: 188b3faa2e8SNicholas Bellinger default: 189b3faa2e8SNicholas Bellinger return DMA_NONE; 190b3faa2e8SNicholas Bellinger } 191b3faa2e8SNicholas Bellinger } 192b3faa2e8SNicholas Bellinger 193c4795fb2SChristoph Hellwig #endif /* TARGET_CORE_FABRICH */ 194