xref: /linux/include/target/target_core_fabric.h (revision def2b339b422070ecb99298a80e4b15033adc0ce)
1c4795fb2SChristoph Hellwig #ifndef TARGET_CORE_FABRIC_H
2c4795fb2SChristoph Hellwig #define TARGET_CORE_FABRIC_H
3c4795fb2SChristoph Hellwig 
4c4795fb2SChristoph Hellwig struct target_core_fabric_ops {
5c4795fb2SChristoph Hellwig 	struct configfs_subsystem *tf_subsys;
6c4795fb2SChristoph Hellwig 	char *(*get_fabric_name)(void);
7c4795fb2SChristoph Hellwig 	u8 (*get_fabric_proto_ident)(struct se_portal_group *);
8c4795fb2SChristoph Hellwig 	char *(*tpg_get_wwn)(struct se_portal_group *);
9c4795fb2SChristoph Hellwig 	u16 (*tpg_get_tag)(struct se_portal_group *);
10c4795fb2SChristoph Hellwig 	u32 (*tpg_get_default_depth)(struct se_portal_group *);
11c4795fb2SChristoph Hellwig 	u32 (*tpg_get_pr_transport_id)(struct se_portal_group *,
12c4795fb2SChristoph Hellwig 				struct se_node_acl *,
13c4795fb2SChristoph Hellwig 				struct t10_pr_registration *, int *,
14c4795fb2SChristoph Hellwig 				unsigned char *);
15c4795fb2SChristoph Hellwig 	u32 (*tpg_get_pr_transport_id_len)(struct se_portal_group *,
16c4795fb2SChristoph Hellwig 				struct se_node_acl *,
17c4795fb2SChristoph Hellwig 				struct t10_pr_registration *, int *);
18c4795fb2SChristoph Hellwig 	char *(*tpg_parse_pr_out_transport_id)(struct se_portal_group *,
19c4795fb2SChristoph Hellwig 				const char *, u32 *, char **);
20c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode)(struct se_portal_group *);
21c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_cache)(struct se_portal_group *);
22c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *);
23c4795fb2SChristoph Hellwig 	int (*tpg_check_prod_mode_write_protect)(struct se_portal_group *);
24c4795fb2SChristoph Hellwig 	/*
25c4795fb2SChristoph Hellwig 	 * Optionally used by fabrics to allow demo-mode login, but not
26c4795fb2SChristoph Hellwig 	 * expose any TPG LUNs, and return 'not connected' in standard
27c4795fb2SChristoph Hellwig 	 * inquiry response
28c4795fb2SChristoph Hellwig 	 */
29c4795fb2SChristoph Hellwig 	int (*tpg_check_demo_mode_login_only)(struct se_portal_group *);
30c4795fb2SChristoph Hellwig 	struct se_node_acl *(*tpg_alloc_fabric_acl)(
31c4795fb2SChristoph Hellwig 					struct se_portal_group *);
32c4795fb2SChristoph Hellwig 	void (*tpg_release_fabric_acl)(struct se_portal_group *,
33c4795fb2SChristoph Hellwig 					struct se_node_acl *);
34c4795fb2SChristoph Hellwig 	u32 (*tpg_get_inst_index)(struct se_portal_group *);
35c4795fb2SChristoph Hellwig 	/*
36c4795fb2SChristoph Hellwig 	 * Optional to release struct se_cmd and fabric dependent allocated
37c4795fb2SChristoph Hellwig 	 * I/O descriptor in transport_cmd_check_stop().
38c4795fb2SChristoph Hellwig 	 *
39c4795fb2SChristoph Hellwig 	 * Returning 1 will signal a descriptor has been released.
40c4795fb2SChristoph Hellwig 	 * Returning 0 will signal a descriptor has not been released.
41c4795fb2SChristoph Hellwig 	 */
42c4795fb2SChristoph Hellwig 	int (*check_stop_free)(struct se_cmd *);
43c4795fb2SChristoph Hellwig 	void (*release_cmd)(struct se_cmd *);
444149268eSJoern Engel 	void (*put_session)(struct se_session *);
45c4795fb2SChristoph Hellwig 	/*
46c4795fb2SChristoph Hellwig 	 * Called with spin_lock_bh(struct se_portal_group->session_lock held.
47c4795fb2SChristoph Hellwig 	 */
48c4795fb2SChristoph Hellwig 	int (*shutdown_session)(struct se_session *);
49c4795fb2SChristoph Hellwig 	void (*close_session)(struct se_session *);
50c4795fb2SChristoph Hellwig 	u32 (*sess_get_index)(struct se_session *);
51c4795fb2SChristoph Hellwig 	/*
52c4795fb2SChristoph Hellwig 	 * Used only for SCSI fabrics that contain multi-value TransportIDs
53c4795fb2SChristoph Hellwig 	 * (like iSCSI).  All other SCSI fabrics should set this to NULL.
54c4795fb2SChristoph Hellwig 	 */
55c4795fb2SChristoph Hellwig 	u32 (*sess_get_initiator_sid)(struct se_session *,
56c4795fb2SChristoph Hellwig 				      unsigned char *, u32);
57c4795fb2SChristoph Hellwig 	int (*write_pending)(struct se_cmd *);
58c4795fb2SChristoph Hellwig 	int (*write_pending_status)(struct se_cmd *);
59c4795fb2SChristoph Hellwig 	void (*set_default_node_attributes)(struct se_node_acl *);
60c4795fb2SChristoph Hellwig 	u32 (*get_task_tag)(struct se_cmd *);
61c4795fb2SChristoph Hellwig 	int (*get_cmd_state)(struct se_cmd *);
62c4795fb2SChristoph Hellwig 	int (*queue_data_in)(struct se_cmd *);
63c4795fb2SChristoph Hellwig 	int (*queue_status)(struct se_cmd *);
64b79fafacSJoern Engel 	void (*queue_tm_rsp)(struct se_cmd *);
65c4795fb2SChristoph Hellwig 	/*
66c4795fb2SChristoph Hellwig 	 * fabric module calls for target_core_fabric_configfs.c
67c4795fb2SChristoph Hellwig 	 */
68c4795fb2SChristoph Hellwig 	struct se_wwn *(*fabric_make_wwn)(struct target_fabric_configfs *,
69c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
70c4795fb2SChristoph Hellwig 	void (*fabric_drop_wwn)(struct se_wwn *);
71c4795fb2SChristoph Hellwig 	struct se_portal_group *(*fabric_make_tpg)(struct se_wwn *,
72c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
73c4795fb2SChristoph Hellwig 	void (*fabric_drop_tpg)(struct se_portal_group *);
74c4795fb2SChristoph Hellwig 	int (*fabric_post_link)(struct se_portal_group *,
75c4795fb2SChristoph Hellwig 				struct se_lun *);
76c4795fb2SChristoph Hellwig 	void (*fabric_pre_unlink)(struct se_portal_group *,
77c4795fb2SChristoph Hellwig 				struct se_lun *);
78c4795fb2SChristoph Hellwig 	struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *,
79c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
80c4795fb2SChristoph Hellwig 	void (*fabric_drop_np)(struct se_tpg_np *);
81c4795fb2SChristoph Hellwig 	struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *,
82c4795fb2SChristoph Hellwig 				struct config_group *, const char *);
83c4795fb2SChristoph Hellwig 	void (*fabric_drop_nodeacl)(struct se_node_acl *);
84c4795fb2SChristoph Hellwig };
85c4795fb2SChristoph Hellwig 
86c4795fb2SChristoph Hellwig struct se_session *transport_init_session(void);
87c0add7fdSNicholas Bellinger int transport_alloc_session_tags(struct se_session *, unsigned int,
88c0add7fdSNicholas Bellinger 		unsigned int);
89c0add7fdSNicholas Bellinger struct se_session *transport_init_session_tags(unsigned int, unsigned int);
90c4795fb2SChristoph Hellwig void	__transport_register_session(struct se_portal_group *,
91c4795fb2SChristoph Hellwig 		struct se_node_acl *, struct se_session *, void *);
92c4795fb2SChristoph Hellwig void	transport_register_session(struct se_portal_group *,
93c4795fb2SChristoph Hellwig 		struct se_node_acl *, struct se_session *, void *);
9441ac82b6SNicholas Bellinger void	target_get_session(struct se_session *);
9533933a0eSJörn Engel void	target_put_session(struct se_session *);
96c4795fb2SChristoph Hellwig void	transport_free_session(struct se_session *);
97afb999ffSNicholas Bellinger void	target_put_nacl(struct se_node_acl *);
98c4795fb2SChristoph Hellwig void	transport_deregister_session_configfs(struct se_session *);
99c4795fb2SChristoph Hellwig void	transport_deregister_session(struct se_session *);
100c4795fb2SChristoph Hellwig 
101c4795fb2SChristoph Hellwig 
102c4795fb2SChristoph Hellwig void	transport_init_se_cmd(struct se_cmd *, struct target_core_fabric_ops *,
103c4795fb2SChristoph Hellwig 		struct se_session *, u32, int, int, unsigned char *);
104de103c93SChristoph Hellwig sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32);
105de103c93SChristoph Hellwig sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
106a026757fSNicholas Bellinger int	target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
107a026757fSNicholas Bellinger 		unsigned char *, unsigned char *, u32, u32, int, int, int,
108*def2b339SNicholas Bellinger 		struct scatterlist *, u32, struct scatterlist *, u32,
109*def2b339SNicholas Bellinger 		struct scatterlist *, u32);
110d6dfc868SRoland Dreier int	target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *,
111a6360785SNicholas Bellinger 		unsigned char *, u32, u32, int, int, int);
112c7042caeSNicholas Bellinger int	target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
113ea98d7f9SAndy Grover 		unsigned char *sense, u32 unpacked_lun,
114c0974f89SNicholas Bellinger 		void *fabric_tmr_ptr, unsigned char tm_type,
115c0974f89SNicholas Bellinger 		gfp_t, unsigned int, int);
116c4795fb2SChristoph Hellwig int	transport_handle_cdb_direct(struct se_cmd *);
117de103c93SChristoph Hellwig sense_reason_t	transport_generic_new_cmd(struct se_cmd *);
118c4795fb2SChristoph Hellwig 
11970baf0abSChristoph Hellwig void	target_execute_cmd(struct se_cmd *cmd);
120c4795fb2SChristoph Hellwig 
121d5ddad41SNicholas Bellinger int	transport_generic_free_cmd(struct se_cmd *, int);
122c4795fb2SChristoph Hellwig 
123c4795fb2SChristoph Hellwig bool	transport_wait_for_tasks(struct se_cmd *);
124c4795fb2SChristoph Hellwig int	transport_check_aborted_status(struct se_cmd *, int);
125de103c93SChristoph Hellwig int	transport_send_check_condition_and_sense(struct se_cmd *,
126de103c93SChristoph Hellwig 		sense_reason_t, int);
12720361e69SNicholas Bellinger int	target_get_sess_cmd(struct se_session *, struct se_cmd *, bool);
128c4795fb2SChristoph Hellwig int	target_put_sess_cmd(struct se_session *, struct se_cmd *);
1291c7b13feSRoland Dreier void	target_sess_cmd_list_set_waiting(struct se_session *);
130be646c2dSJoern Engel void	target_wait_for_sess_cmds(struct se_session *);
131c4795fb2SChristoph Hellwig 
132c4795fb2SChristoph Hellwig int	core_alua_check_nonop_delay(struct se_cmd *);
133c4795fb2SChristoph Hellwig 
134c8e31f26SAndy Grover int	core_tmr_alloc_req(struct se_cmd *, void *, u8, gfp_t);
135c4795fb2SChristoph Hellwig void	core_tmr_release_req(struct se_tmr_req *);
136c4795fb2SChristoph Hellwig int	transport_generic_handle_tmr(struct se_cmd *);
137de103c93SChristoph Hellwig void	transport_generic_request_failure(struct se_cmd *, sense_reason_t);
13876dde50eSNicholas Bellinger void	__target_execute_cmd(struct se_cmd *);
139c4795fb2SChristoph Hellwig int	transport_lookup_tmr_lun(struct se_cmd *, u32);
140c4795fb2SChristoph Hellwig 
141b3fde035SThomas Glanzmann struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
142b3fde035SThomas Glanzmann 		unsigned char *);
143c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *,
144c4795fb2SChristoph Hellwig 		unsigned char *);
145c4795fb2SChristoph Hellwig void	core_tpg_clear_object_luns(struct se_portal_group *);
146c4795fb2SChristoph Hellwig struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *,
147c4795fb2SChristoph Hellwig 		struct se_node_acl *, const char *, u32);
148c4795fb2SChristoph Hellwig int	core_tpg_del_initiator_node_acl(struct se_portal_group *,
149c4795fb2SChristoph Hellwig 		struct se_node_acl *, int);
150c4795fb2SChristoph Hellwig int	core_tpg_set_initiator_node_queue_depth(struct se_portal_group *,
151c4795fb2SChristoph Hellwig 		unsigned char *, u32, int);
15279e62fc3SAndy Grover int	core_tpg_set_initiator_node_tag(struct se_portal_group *,
15379e62fc3SAndy Grover 		struct se_node_acl *, const char *);
154c4795fb2SChristoph Hellwig int	core_tpg_register(struct target_core_fabric_ops *, struct se_wwn *,
155c4795fb2SChristoph Hellwig 		struct se_portal_group *, void *, int);
156c4795fb2SChristoph Hellwig int	core_tpg_deregister(struct se_portal_group *);
157c4795fb2SChristoph Hellwig 
158c4795fb2SChristoph Hellwig /* SAS helpers */
159c4795fb2SChristoph Hellwig u8	sas_get_fabric_proto_ident(struct se_portal_group *);
160c4795fb2SChristoph Hellwig u32	sas_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
161c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
162c4795fb2SChristoph Hellwig u32	sas_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
163c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
164c4795fb2SChristoph Hellwig char	*sas_parse_pr_out_transport_id(struct se_portal_group *, const char *,
165c4795fb2SChristoph Hellwig 		u32 *, char **);
166c4795fb2SChristoph Hellwig 
167c4795fb2SChristoph Hellwig /* FC helpers */
168c4795fb2SChristoph Hellwig u8	fc_get_fabric_proto_ident(struct se_portal_group *);
169c4795fb2SChristoph Hellwig u32	fc_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
170c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
171c4795fb2SChristoph Hellwig u32	fc_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
172c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
173c4795fb2SChristoph Hellwig char	*fc_parse_pr_out_transport_id(struct se_portal_group *, const char *,
174c4795fb2SChristoph Hellwig 		u32 *, char **);
175c4795fb2SChristoph Hellwig 
176c4795fb2SChristoph Hellwig /* iSCSI helpers */
177c4795fb2SChristoph Hellwig u8	iscsi_get_fabric_proto_ident(struct se_portal_group *);
178c4795fb2SChristoph Hellwig u32	iscsi_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
179c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *, unsigned char *);
180c4795fb2SChristoph Hellwig u32	iscsi_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
181c4795fb2SChristoph Hellwig 		struct t10_pr_registration *, int *);
182c4795fb2SChristoph Hellwig char	*iscsi_parse_pr_out_transport_id(struct se_portal_group *, const char *,
183c4795fb2SChristoph Hellwig 		u32 *, char **);
184c4795fb2SChristoph Hellwig 
185b3faa2e8SNicholas Bellinger /*
186b3faa2e8SNicholas Bellinger  * The LIO target core uses DMA_TO_DEVICE to mean that data is going
187b3faa2e8SNicholas Bellinger  * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean
188b3faa2e8SNicholas Bellinger  * that data is coming from the target (eg handling a READ).  However,
189b3faa2e8SNicholas Bellinger  * this is just the opposite of what we have to tell the DMA mapping
190b3faa2e8SNicholas Bellinger  * layer -- eg when handling a READ, the HBA will have to DMA the data
191b3faa2e8SNicholas Bellinger  * out of memory so it can send it to the initiator, which means we
192b3faa2e8SNicholas Bellinger  * need to use DMA_TO_DEVICE when we map the data.
193b3faa2e8SNicholas Bellinger  */
194b3faa2e8SNicholas Bellinger static inline enum dma_data_direction
195b3faa2e8SNicholas Bellinger target_reverse_dma_direction(struct se_cmd *se_cmd)
196b3faa2e8SNicholas Bellinger {
197b3faa2e8SNicholas Bellinger 	if (se_cmd->se_cmd_flags & SCF_BIDI)
198b3faa2e8SNicholas Bellinger 		return DMA_BIDIRECTIONAL;
199b3faa2e8SNicholas Bellinger 
200b3faa2e8SNicholas Bellinger 	switch (se_cmd->data_direction) {
201b3faa2e8SNicholas Bellinger 	case DMA_TO_DEVICE:
202b3faa2e8SNicholas Bellinger 		return DMA_FROM_DEVICE;
203b3faa2e8SNicholas Bellinger 	case DMA_FROM_DEVICE:
204b3faa2e8SNicholas Bellinger 		return DMA_TO_DEVICE;
205b3faa2e8SNicholas Bellinger 	case DMA_NONE:
206b3faa2e8SNicholas Bellinger 	default:
207b3faa2e8SNicholas Bellinger 		return DMA_NONE;
208b3faa2e8SNicholas Bellinger 	}
209b3faa2e8SNicholas Bellinger }
210b3faa2e8SNicholas Bellinger 
211c4795fb2SChristoph Hellwig #endif /* TARGET_CORE_FABRICH */
212