xref: /linux/include/target/target_core_fabric.h (revision afc16604c06414223478df3e42301ab630b9960a)
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;
7c4795fb2SChristoph Hellwig 	char *(*get_fabric_name)(void);
8c4795fb2SChristoph Hellwig 	u8 (*get_fabric_proto_ident)(struct se_portal_group *);
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 	u32 (*tpg_get_pr_transport_id)(struct se_portal_group *,
13c4795fb2SChristoph Hellwig 				struct se_node_acl *,
14c4795fb2SChristoph Hellwig 				struct t10_pr_registration *, int *,
15c4795fb2SChristoph Hellwig 				unsigned char *);
16c4795fb2SChristoph Hellwig 	u32 (*tpg_get_pr_transport_id_len)(struct se_portal_group *,
17c4795fb2SChristoph Hellwig 				struct se_node_acl *,
18c4795fb2SChristoph Hellwig 				struct t10_pr_registration *, int *);
19c4795fb2SChristoph Hellwig 	char *(*tpg_parse_pr_out_transport_id)(struct se_portal_group *,
20c4795fb2SChristoph Hellwig 				const char *, u32 *, char **);
21c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode)(struct se_portal_group *);
22c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_cache)(struct se_portal_group *);
23c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *);
24c4795fb2SChristoph Hellwig 	int (*tpg_check_prod_mode_write_protect)(struct se_portal_group *);
25c4795fb2SChristoph Hellwig 	/*
26c4795fb2SChristoph Hellwig 	 * Optionally used by fabrics to allow demo-mode login, but not
27c4795fb2SChristoph Hellwig 	 * expose any TPG LUNs, and return 'not connected' in standard
28c4795fb2SChristoph Hellwig 	 * inquiry response
29c4795fb2SChristoph Hellwig 	 */
30c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_login_only)(struct se_portal_group *);
3138b57f82SNicholas Bellinger 	/*
3238b57f82SNicholas Bellinger 	 * Optionally used as a configfs tunable to determine when
3338b57f82SNicholas Bellinger 	 * target-core should signal the PROTECT=1 feature bit for
3438b57f82SNicholas Bellinger 	 * backends that don't support T10-PI, so that either fabric
3538b57f82SNicholas Bellinger 	 * HW offload or target-core emulation performs the associated
3638b57f82SNicholas Bellinger 	 * WRITE_STRIP and READ_INSERT operations.
3738b57f82SNicholas Bellinger 	 */
3838b57f82SNicholas Bellinger 	int (*tpg_check_prot_fabric_only)(struct se_portal_group *);
39c4795fb2SChristoph Hellwig 	struct se_node_acl *(*tpg_alloc_fabric_acl)(
40c4795fb2SChristoph Hellwig 					struct se_portal_group *);
41c4795fb2SChristoph Hellwig 	void (*tpg_release_fabric_acl)(struct se_portal_group *,
42c4795fb2SChristoph Hellwig 					struct se_node_acl *);
43c4795fb2SChristoph Hellwig 	u32 (*tpg_get_inst_index)(struct se_portal_group *);
44c4795fb2SChristoph Hellwig 	/*
45c4795fb2SChristoph Hellwig 	 * Optional to release struct se_cmd and fabric dependent allocated
46c4795fb2SChristoph Hellwig 	 * I/O descriptor in transport_cmd_check_stop().
47c4795fb2SChristoph Hellwig 	 *
48c4795fb2SChristoph Hellwig 	 * Returning 1 will signal a descriptor has been released.
49c4795fb2SChristoph Hellwig 	 * Returning 0 will signal a descriptor has not been released.
50c4795fb2SChristoph Hellwig 	 */
51c4795fb2SChristoph Hellwig 	int (*check_stop_free)(struct se_cmd *);
52c4795fb2SChristoph Hellwig 	void (*release_cmd)(struct se_cmd *);
534149268eSJoern Engel 	void (*put_session)(struct se_session *);
54c4795fb2SChristoph Hellwig 	/*
55c4795fb2SChristoph Hellwig 	 * Called with spin_lock_bh(struct se_portal_group->session_lock held.
56c4795fb2SChristoph Hellwig 	 */
57c4795fb2SChristoph Hellwig 	int (*shutdown_session)(struct se_session *);
58c4795fb2SChristoph Hellwig 	void (*close_session)(struct se_session *);
59c4795fb2SChristoph Hellwig 	u32 (*sess_get_index)(struct se_session *);
60c4795fb2SChristoph Hellwig 	/*
61c4795fb2SChristoph Hellwig 	 * Used only for SCSI fabrics that contain multi-value TransportIDs
62c4795fb2SChristoph Hellwig 	 * (like iSCSI).  All other SCSI fabrics should set this to NULL.
63c4795fb2SChristoph Hellwig 	 */
64c4795fb2SChristoph Hellwig 	u32 (*sess_get_initiator_sid)(struct se_session *,
65c4795fb2SChristoph Hellwig 				      unsigned char *, u32);
66c4795fb2SChristoph Hellwig 	int (*write_pending)(struct se_cmd *);
67c4795fb2SChristoph Hellwig 	int (*write_pending_status)(struct se_cmd *);
68c4795fb2SChristoph Hellwig 	void (*set_default_node_attributes)(struct se_node_acl *);
69c4795fb2SChristoph Hellwig 	u32 (*get_task_tag)(struct se_cmd *);
70c4795fb2SChristoph Hellwig 	int (*get_cmd_state)(struct se_cmd *);
71c4795fb2SChristoph Hellwig 	int (*queue_data_in)(struct se_cmd *);
72c4795fb2SChristoph Hellwig 	int (*queue_status)(struct se_cmd *);
73b79fafacSJoern Engel 	void (*queue_tm_rsp)(struct se_cmd *);
74131e6abcSNicholas Bellinger 	void (*aborted_task)(struct se_cmd *);
75c4795fb2SChristoph Hellwig 	/*
76c4795fb2SChristoph Hellwig 	 * fabric module calls for target_core_fabric_configfs.c
77c4795fb2SChristoph Hellwig 	 */
78c4795fb2SChristoph Hellwig 	struct se_wwn *(*fabric_make_wwn)(struct target_fabric_configfs *,
79c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
80c4795fb2SChristoph Hellwig 	void (*fabric_drop_wwn)(struct se_wwn *);
81c4795fb2SChristoph Hellwig 	struct se_portal_group *(*fabric_make_tpg)(struct se_wwn *,
82c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
83c4795fb2SChristoph Hellwig 	void (*fabric_drop_tpg)(struct se_portal_group *);
84c4795fb2SChristoph Hellwig 	int (*fabric_post_link)(struct se_portal_group *,
85c4795fb2SChristoph Hellwig 				struct se_lun *);
86c4795fb2SChristoph Hellwig 	void (*fabric_pre_unlink)(struct se_portal_group *,
87c4795fb2SChristoph Hellwig 				struct se_lun *);
88c4795fb2SChristoph Hellwig 	struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *,
89c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
90c4795fb2SChristoph Hellwig 	void (*fabric_drop_np)(struct se_tpg_np *);
91c4795fb2SChristoph Hellwig 	struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *,
92c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
93c4795fb2SChristoph Hellwig 	void (*fabric_drop_nodeacl)(struct se_node_acl *);
949ac8928eSChristoph Hellwig 
959ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_discovery_attrs;
969ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_wwn_attrs;
979ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_base_attrs;
989ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_np_base_attrs;
999ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_attrib_attrs;
1009ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_auth_attrs;
1019ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_param_attrs;
1029ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_nacl_base_attrs;
1039ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_nacl_attrib_attrs;
1049ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_nacl_auth_attrs;
1059ac8928eSChristoph Hellwig 	struct configfs_attribute **tfc_tpg_nacl_param_attrs;
106c4795fb2SChristoph Hellwig };
107c4795fb2SChristoph Hellwig 
1089ac8928eSChristoph Hellwig int target_register_template(const struct target_core_fabric_ops *fo);
1099ac8928eSChristoph Hellwig void target_unregister_template(const struct target_core_fabric_ops *fo);
1109ac8928eSChristoph Hellwig 
111d588cf8fSChristoph Hellwig int target_depend_item(struct config_item *item);
112d588cf8fSChristoph Hellwig void target_undepend_item(struct config_item *item);
113d588cf8fSChristoph Hellwig 
114e70beee7SNicholas Bellinger struct se_session *transport_init_session(enum target_prot_op);
115c0add7fdSNicholas Bellinger int transport_alloc_session_tags(struct se_session *, unsigned int,
116c0add7fdSNicholas Bellinger 		unsigned int);
117e70beee7SNicholas Bellinger struct se_session *transport_init_session_tags(unsigned int, unsigned int,
118e70beee7SNicholas Bellinger 		enum target_prot_op);
119c4795fb2SChristoph Hellwig void	__transport_register_session(struct se_portal_group *,
120c4795fb2SChristoph Hellwig 		struct se_node_acl *, struct se_session *, void *);
121c4795fb2SChristoph Hellwig void	transport_register_session(struct se_portal_group *,
122c4795fb2SChristoph Hellwig 		struct se_node_acl *, struct se_session *, void *);
12341ac82b6SNicholas Bellinger void	target_get_session(struct se_session *);
12433933a0eSJörn Engel void	target_put_session(struct se_session *);
125f8e471f9SNicholas Bellinger ssize_t	target_show_dynamic_sessions(struct se_portal_group *, char *);
126c4795fb2SChristoph Hellwig void	transport_free_session(struct se_session *);
127afb999ffSNicholas Bellinger void	target_put_nacl(struct se_node_acl *);
128c4795fb2SChristoph Hellwig void	transport_deregister_session_configfs(struct se_session *);
129c4795fb2SChristoph Hellwig void	transport_deregister_session(struct se_session *);
130c4795fb2SChristoph Hellwig 
131c4795fb2SChristoph Hellwig 
1329ac8928eSChristoph Hellwig void	transport_init_se_cmd(struct se_cmd *,
1339ac8928eSChristoph Hellwig 		const struct target_core_fabric_ops *,
134c4795fb2SChristoph Hellwig 		struct se_session *, u32, int, int, unsigned char *);
135de103c93SChristoph Hellwig sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32);
136de103c93SChristoph Hellwig sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
137a026757fSNicholas Bellinger int	target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
138a026757fSNicholas Bellinger 		unsigned char *, unsigned char *, u32, u32, int, int, int,
139def2b339SNicholas Bellinger 		struct scatterlist *, u32, struct scatterlist *, u32,
140def2b339SNicholas Bellinger 		struct scatterlist *, u32);
141d6dfc868SRoland Dreier int	target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *,
142a6360785SNicholas Bellinger 		unsigned char *, u32, u32, int, int, int);
143c7042caeSNicholas Bellinger int	target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
144ea98d7f9SAndy Grover 		unsigned char *sense, u32 unpacked_lun,
145c0974f89SNicholas Bellinger 		void *fabric_tmr_ptr, unsigned char tm_type,
146c0974f89SNicholas Bellinger 		gfp_t, unsigned int, int);
147c4795fb2SChristoph Hellwig int	transport_handle_cdb_direct(struct se_cmd *);
148de103c93SChristoph Hellwig sense_reason_t	transport_generic_new_cmd(struct se_cmd *);
149c4795fb2SChristoph Hellwig 
15070baf0abSChristoph Hellwig void	target_execute_cmd(struct se_cmd *cmd);
151c4795fb2SChristoph Hellwig 
152d5ddad41SNicholas Bellinger int	transport_generic_free_cmd(struct se_cmd *, int);
153c4795fb2SChristoph Hellwig 
154c4795fb2SChristoph Hellwig bool	transport_wait_for_tasks(struct se_cmd *);
155c4795fb2SChristoph Hellwig int	transport_check_aborted_status(struct se_cmd *, int);
156de103c93SChristoph Hellwig int	transport_send_check_condition_and_sense(struct se_cmd *,
157de103c93SChristoph Hellwig 		sense_reason_t, int);
158*afc16604SBart Van Assche int	target_get_sess_cmd(struct se_cmd *, bool);
159*afc16604SBart Van Assche int	target_put_sess_cmd(struct se_cmd *);
1601c7b13feSRoland Dreier void	target_sess_cmd_list_set_waiting(struct se_session *);
161be646c2dSJoern Engel void	target_wait_for_sess_cmds(struct se_session *);
162c4795fb2SChristoph Hellwig 
163c4795fb2SChristoph Hellwig int	core_alua_check_nonop_delay(struct se_cmd *);
164c4795fb2SChristoph Hellwig 
165c8e31f26SAndy Grover int	core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t);
166c4795fb2SChristoph Hellwig void	core_tmr_release_req(struct se_tmr_req *);
167c4795fb2SChristoph Hellwig int	transport_generic_handle_tmr(struct se_cmd *);
168de103c93SChristoph Hellwig void	transport_generic_request_failure(struct se_cmd *, sense_reason_t);
16976dde50eSNicholas Bellinger void	__target_execute_cmd(struct se_cmd *);
170c4795fb2SChristoph Hellwig int	transport_lookup_tmr_lun(struct se_cmd *, u32);
171c4795fb2SChristoph Hellwig 
172b3fde035SThomas Glanzmann struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
173b3fde035SThomas Glanzmann 		unsigned char *);
174c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *,
175c4795fb2SChristoph Hellwig 		unsigned char *);
176c4795fb2SChristoph Hellwig void	core_tpg_clear_object_luns(struct se_portal_group *);
177c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *,
178c4795fb2SChristoph Hellwig 		struct se_node_acl *, const char *, u32);
179c4795fb2SChristoph Hellwig int	core_tpg_del_initiator_node_acl(struct se_portal_group *,
180c4795fb2SChristoph Hellwig 		struct se_node_acl *, int);
181c4795fb2SChristoph Hellwig int	core_tpg_set_initiator_node_queue_depth(struct se_portal_group *,
182c4795fb2SChristoph Hellwig 		unsigned char *, u32, int);
18379e62fc3SAndy Grover int	core_tpg_set_initiator_node_tag(struct se_portal_group *,
18479e62fc3SAndy Grover 		struct se_node_acl *, const char *);
1859ac8928eSChristoph Hellwig int	core_tpg_register(const struct target_core_fabric_ops *,
1869ac8928eSChristoph Hellwig 		struct se_wwn *, struct se_portal_group *, void *, int);
187c4795fb2SChristoph Hellwig int	core_tpg_deregister(struct se_portal_group *);
188c4795fb2SChristoph Hellwig 
189c4795fb2SChristoph Hellwig /* SAS helpers */
190c4795fb2SChristoph Hellwig u8	sas_get_fabric_proto_ident(struct se_portal_group *);
191c4795fb2SChristoph Hellwig u32	sas_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
192c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
193c4795fb2SChristoph Hellwig u32	sas_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
194c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
195c4795fb2SChristoph Hellwig char	*sas_parse_pr_out_transport_id(struct se_portal_group *, const char *,
196c4795fb2SChristoph Hellwig 		u32 *, char **);
197c4795fb2SChristoph Hellwig 
198c4795fb2SChristoph Hellwig /* FC helpers */
199c4795fb2SChristoph Hellwig u8	fc_get_fabric_proto_ident(struct se_portal_group *);
200c4795fb2SChristoph Hellwig u32	fc_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
201c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
202c4795fb2SChristoph Hellwig u32	fc_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
203c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
204c4795fb2SChristoph Hellwig char	*fc_parse_pr_out_transport_id(struct se_portal_group *, const char *,
205c4795fb2SChristoph Hellwig 		u32 *, char **);
206c4795fb2SChristoph Hellwig 
207c4795fb2SChristoph Hellwig /* iSCSI helpers */
208c4795fb2SChristoph Hellwig u8	iscsi_get_fabric_proto_ident(struct se_portal_group *);
209c4795fb2SChristoph Hellwig u32	iscsi_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
210c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
211c4795fb2SChristoph Hellwig u32	iscsi_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
212c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
213c4795fb2SChristoph Hellwig char	*iscsi_parse_pr_out_transport_id(struct se_portal_group *, const char *,
214c4795fb2SChristoph Hellwig 		u32 *, char **);
215c4795fb2SChristoph Hellwig 
216b3faa2e8SNicholas Bellinger /*
217b3faa2e8SNicholas Bellinger  * The LIO target core uses DMA_TO_DEVICE to mean that data is going
218b3faa2e8SNicholas Bellinger  * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean
219b3faa2e8SNicholas Bellinger  * that data is coming from the target (eg handling a READ).  However,
220b3faa2e8SNicholas Bellinger  * this is just the opposite of what we have to tell the DMA mapping
221b3faa2e8SNicholas Bellinger  * layer -- eg when handling a READ, the HBA will have to DMA the data
222b3faa2e8SNicholas Bellinger  * out of memory so it can send it to the initiator, which means we
223b3faa2e8SNicholas Bellinger  * need to use DMA_TO_DEVICE when we map the data.
224b3faa2e8SNicholas Bellinger  */
225b3faa2e8SNicholas Bellinger static inline enum dma_data_direction
226b3faa2e8SNicholas Bellinger target_reverse_dma_direction(struct se_cmd *se_cmd)
227b3faa2e8SNicholas Bellinger {
228b3faa2e8SNicholas Bellinger 	if (se_cmd->se_cmd_flags & SCF_BIDI)
229b3faa2e8SNicholas Bellinger 		return DMA_BIDIRECTIONAL;
230b3faa2e8SNicholas Bellinger 
231b3faa2e8SNicholas Bellinger 	switch (se_cmd->data_direction) {
232b3faa2e8SNicholas Bellinger 	case DMA_TO_DEVICE:
233b3faa2e8SNicholas Bellinger 		return DMA_FROM_DEVICE;
234b3faa2e8SNicholas Bellinger 	case DMA_FROM_DEVICE:
235b3faa2e8SNicholas Bellinger 		return DMA_TO_DEVICE;
236b3faa2e8SNicholas Bellinger 	case DMA_NONE:
237b3faa2e8SNicholas Bellinger 	default:
238b3faa2e8SNicholas Bellinger 		return DMA_NONE;
239b3faa2e8SNicholas Bellinger 	}
240b3faa2e8SNicholas Bellinger }
241b3faa2e8SNicholas Bellinger 
242c4795fb2SChristoph Hellwig #endif /* TARGET_CORE_FABRICH */
243