0001
0002 #ifndef TARGET_CORE_FABRIC_H
0003 #define TARGET_CORE_FABRIC_H
0004
0005 #include <linux/configfs.h>
0006 #include <linux/types.h>
0007 #include <target/target_core_base.h>
0008
0009 struct target_core_fabric_ops {
0010 struct module *module;
0011
0012
0013
0014
0015
0016 const char *fabric_alias;
0017
0018
0019
0020
0021
0022 const char *fabric_name;
0023 size_t node_acl_size;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 u32 max_data_sg_nents;
0037 char *(*tpg_get_wwn)(struct se_portal_group *);
0038 u16 (*tpg_get_tag)(struct se_portal_group *);
0039 u32 (*tpg_get_default_depth)(struct se_portal_group *);
0040 int (*tpg_check_demo_mode)(struct se_portal_group *);
0041 int (*tpg_check_demo_mode_cache)(struct se_portal_group *);
0042 int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *);
0043 int (*tpg_check_prod_mode_write_protect)(struct se_portal_group *);
0044
0045
0046
0047
0048
0049 int (*tpg_check_demo_mode_login_only)(struct se_portal_group *);
0050
0051
0052
0053
0054
0055
0056
0057 int (*tpg_check_prot_fabric_only)(struct se_portal_group *);
0058 u32 (*tpg_get_inst_index)(struct se_portal_group *);
0059
0060
0061
0062
0063
0064
0065
0066 int (*check_stop_free)(struct se_cmd *);
0067 void (*release_cmd)(struct se_cmd *);
0068 void (*close_session)(struct se_session *);
0069 u32 (*sess_get_index)(struct se_session *);
0070
0071
0072
0073
0074 u32 (*sess_get_initiator_sid)(struct se_session *,
0075 unsigned char *, u32);
0076 int (*write_pending)(struct se_cmd *);
0077 void (*set_default_node_attributes)(struct se_node_acl *);
0078 int (*get_cmd_state)(struct se_cmd *);
0079 int (*queue_data_in)(struct se_cmd *);
0080 int (*queue_status)(struct se_cmd *);
0081 void (*queue_tm_rsp)(struct se_cmd *);
0082 void (*aborted_task)(struct se_cmd *);
0083
0084
0085
0086 struct se_wwn *(*fabric_make_wwn)(struct target_fabric_configfs *,
0087 struct config_group *, const char *);
0088 void (*fabric_drop_wwn)(struct se_wwn *);
0089 void (*add_wwn_groups)(struct se_wwn *);
0090 struct se_portal_group *(*fabric_make_tpg)(struct se_wwn *,
0091 const char *);
0092 int (*fabric_enable_tpg)(struct se_portal_group *se_tpg, bool enable);
0093 void (*fabric_drop_tpg)(struct se_portal_group *);
0094 int (*fabric_post_link)(struct se_portal_group *,
0095 struct se_lun *);
0096 void (*fabric_pre_unlink)(struct se_portal_group *,
0097 struct se_lun *);
0098 struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *,
0099 struct config_group *, const char *);
0100 void (*fabric_drop_np)(struct se_tpg_np *);
0101 int (*fabric_init_nodeacl)(struct se_node_acl *, const char *);
0102
0103 struct configfs_attribute **tfc_discovery_attrs;
0104 struct configfs_attribute **tfc_wwn_attrs;
0105 struct configfs_attribute **tfc_tpg_base_attrs;
0106 struct configfs_attribute **tfc_tpg_np_base_attrs;
0107 struct configfs_attribute **tfc_tpg_attrib_attrs;
0108 struct configfs_attribute **tfc_tpg_auth_attrs;
0109 struct configfs_attribute **tfc_tpg_param_attrs;
0110 struct configfs_attribute **tfc_tpg_nacl_base_attrs;
0111 struct configfs_attribute **tfc_tpg_nacl_attrib_attrs;
0112 struct configfs_attribute **tfc_tpg_nacl_auth_attrs;
0113 struct configfs_attribute **tfc_tpg_nacl_param_attrs;
0114
0115
0116
0117
0118
0119
0120 bool write_pending_must_be_called;
0121 };
0122
0123 int target_register_template(const struct target_core_fabric_ops *fo);
0124 void target_unregister_template(const struct target_core_fabric_ops *fo);
0125
0126 int target_depend_item(struct config_item *item);
0127 void target_undepend_item(struct config_item *item);
0128
0129 struct se_session *target_setup_session(struct se_portal_group *,
0130 unsigned int, unsigned int, enum target_prot_op prot_op,
0131 const char *, void *,
0132 int (*callback)(struct se_portal_group *,
0133 struct se_session *, void *));
0134 void target_remove_session(struct se_session *);
0135
0136 int transport_init_session(struct se_session *se_sess);
0137 struct se_session *transport_alloc_session(enum target_prot_op);
0138 int transport_alloc_session_tags(struct se_session *, unsigned int,
0139 unsigned int);
0140 void __transport_register_session(struct se_portal_group *,
0141 struct se_node_acl *, struct se_session *, void *);
0142 void transport_register_session(struct se_portal_group *,
0143 struct se_node_acl *, struct se_session *, void *);
0144 ssize_t target_show_dynamic_sessions(struct se_portal_group *, char *);
0145 void transport_free_session(struct se_session *);
0146 void target_spc2_release(struct se_node_acl *nacl);
0147 void target_put_nacl(struct se_node_acl *);
0148 void transport_deregister_session_configfs(struct se_session *);
0149 void transport_deregister_session(struct se_session *);
0150
0151
0152 void __target_init_cmd(struct se_cmd *,
0153 const struct target_core_fabric_ops *,
0154 struct se_session *, u32, int, int, unsigned char *, u64);
0155 int target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess,
0156 unsigned char *sense, u64 unpacked_lun, u32 data_length,
0157 int task_attr, int data_dir, int flags);
0158 int target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb,
0159 struct scatterlist *sgl, u32 sgl_count,
0160 struct scatterlist *sgl_bidi, u32 sgl_bidi_count,
0161 struct scatterlist *sgl_prot, u32 sgl_prot_count, gfp_t gfp);
0162 void target_submit(struct se_cmd *se_cmd);
0163 sense_reason_t transport_lookup_cmd_lun(struct se_cmd *);
0164 sense_reason_t target_cmd_init_cdb(struct se_cmd *se_cmd, unsigned char *cdb,
0165 gfp_t gfp);
0166 sense_reason_t target_cmd_parse_cdb(struct se_cmd *);
0167 void target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *,
0168 unsigned char *, u64, u32, int, int, int);
0169 void target_queue_submission(struct se_cmd *se_cmd);
0170
0171 int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
0172 unsigned char *sense, u64 unpacked_lun,
0173 void *fabric_tmr_ptr, unsigned char tm_type,
0174 gfp_t, u64, int);
0175 int transport_handle_cdb_direct(struct se_cmd *);
0176 sense_reason_t transport_generic_new_cmd(struct se_cmd *);
0177
0178 void target_put_cmd_and_wait(struct se_cmd *cmd);
0179 void target_execute_cmd(struct se_cmd *cmd);
0180
0181 int transport_generic_free_cmd(struct se_cmd *, int);
0182
0183 bool transport_wait_for_tasks(struct se_cmd *);
0184 int transport_send_check_condition_and_sense(struct se_cmd *,
0185 sense_reason_t, int);
0186 int target_send_busy(struct se_cmd *cmd);
0187 int target_get_sess_cmd(struct se_cmd *, bool);
0188 int target_put_sess_cmd(struct se_cmd *);
0189 void target_stop_session(struct se_session *se_sess);
0190 void target_wait_for_sess_cmds(struct se_session *);
0191 void target_show_cmd(const char *pfx, struct se_cmd *cmd);
0192
0193 int core_alua_check_nonop_delay(struct se_cmd *);
0194
0195 int core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t);
0196 void core_tmr_release_req(struct se_tmr_req *);
0197 int transport_generic_handle_tmr(struct se_cmd *);
0198 void transport_generic_request_failure(struct se_cmd *, sense_reason_t);
0199 int transport_lookup_tmr_lun(struct se_cmd *);
0200 void core_allocate_nexus_loss_ua(struct se_node_acl *acl);
0201
0202 struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
0203 unsigned char *);
0204 bool target_tpg_has_node_acl(struct se_portal_group *tpg,
0205 const char *);
0206 struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *,
0207 unsigned char *);
0208 int core_tpg_set_initiator_node_queue_depth(struct se_node_acl *, u32);
0209 int core_tpg_set_initiator_node_tag(struct se_portal_group *,
0210 struct se_node_acl *, const char *);
0211 int core_tpg_register(struct se_wwn *, struct se_portal_group *, int);
0212 int core_tpg_deregister(struct se_portal_group *);
0213
0214 int target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents,
0215 u32 length, bool zero_page, bool chainable);
0216 void target_free_sgl(struct scatterlist *sgl, int nents);
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 static inline enum dma_data_direction
0228 target_reverse_dma_direction(struct se_cmd *se_cmd)
0229 {
0230 if (se_cmd->se_cmd_flags & SCF_BIDI)
0231 return DMA_BIDIRECTIONAL;
0232
0233 switch (se_cmd->data_direction) {
0234 case DMA_TO_DEVICE:
0235 return DMA_FROM_DEVICE;
0236 case DMA_FROM_DEVICE:
0237 return DMA_TO_DEVICE;
0238 case DMA_NONE:
0239 default:
0240 return DMA_NONE;
0241 }
0242 }
0243
0244 #endif