1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2e26d99aeSChristoph Hellwig #ifndef TARGET_CORE_INTERNAL_H
3e26d99aeSChristoph Hellwig #define TARGET_CORE_INTERNAL_H
4e26d99aeSChristoph Hellwig 
58dcf07beSBart Van Assche #include <linux/configfs.h>
68dcf07beSBart Van Assche #include <linux/list.h>
78dcf07beSBart Van Assche #include <linux/types.h>
88dcf07beSBart Van Assche #include <target/target_core_base.h>
98dcf07beSBart Van Assche 
106de2ce5bSChristoph Hellwig #define TARGET_CORE_NAME_MAX_LEN	64
116de2ce5bSChristoph Hellwig #define TARGET_FABRIC_NAME_SIZE		32
126de2ce5bSChristoph Hellwig 
130a06d430SChristoph Hellwig struct target_backend {
140a06d430SChristoph Hellwig 	struct list_head list;
150a06d430SChristoph Hellwig 
160a06d430SChristoph Hellwig 	const struct target_backend_ops *ops;
170a06d430SChristoph Hellwig 
180a06d430SChristoph Hellwig 	struct config_item_type tb_dev_cit;
190a06d430SChristoph Hellwig 	struct config_item_type tb_dev_attrib_cit;
208dc31ff9SMike Christie 	struct config_item_type tb_dev_action_cit;
210a06d430SChristoph Hellwig 	struct config_item_type tb_dev_pr_cit;
220a06d430SChristoph Hellwig 	struct config_item_type tb_dev_wwn_cit;
230a06d430SChristoph Hellwig 	struct config_item_type tb_dev_alua_tg_pt_gps_cit;
240a06d430SChristoph Hellwig 	struct config_item_type tb_dev_stat_cit;
250a06d430SChristoph Hellwig };
260a06d430SChristoph Hellwig 
276de2ce5bSChristoph Hellwig struct target_fabric_configfs {
286de2ce5bSChristoph Hellwig 	atomic_t		tf_access_cnt;
296de2ce5bSChristoph Hellwig 	struct list_head	tf_list;
306de2ce5bSChristoph Hellwig 	struct config_group	tf_group;
316de2ce5bSChristoph Hellwig 	struct config_group	tf_disc_group;
326de2ce5bSChristoph Hellwig 	const struct target_core_fabric_ops *tf_ops;
336de2ce5bSChristoph Hellwig 
346de2ce5bSChristoph Hellwig 	struct config_item_type tf_discovery_cit;
356de2ce5bSChristoph Hellwig 	struct config_item_type	tf_wwn_cit;
366de2ce5bSChristoph Hellwig 	struct config_item_type tf_wwn_fabric_stats_cit;
3739ae3eddSMike Christie 	struct config_item_type tf_wwn_param_cit;
386de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_cit;
396de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_base_cit;
406de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_lun_cit;
416de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_port_cit;
426de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_port_stat_cit;
436de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_np_cit;
446de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_np_base_cit;
456de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_attrib_cit;
466de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_auth_cit;
476de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_param_cit;
486de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_cit;
496de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_base_cit;
506de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_attrib_cit;
516de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_auth_cit;
526de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_param_cit;
536de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_nacl_stat_cit;
546de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_mappedlun_cit;
556de2ce5bSChristoph Hellwig 	struct config_item_type tf_tpg_mappedlun_stat_cit;
566de2ce5bSChristoph Hellwig };
576de2ce5bSChristoph Hellwig 
58e26d99aeSChristoph Hellwig /* target_core_alua.c */
59e26d99aeSChristoph Hellwig extern struct t10_alua_lu_gp *default_lu_gp;
60e26d99aeSChristoph Hellwig 
61e26d99aeSChristoph Hellwig /* target_core_device.c */
62adf653f9SChristoph Hellwig struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16);
63e26d99aeSChristoph Hellwig void	target_pr_kref_release(struct kref *);
6429a05deeSNicholas Bellinger void	core_free_device_list_for_node(struct se_node_acl *,
6529a05deeSNicholas Bellinger 		struct se_portal_group *);
66e26d99aeSChristoph Hellwig void	core_update_device_list_access(u64, bool, struct se_node_acl *);
6703a68b44SAndy Grover struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u64);
68f2d30680SHannes Reinecke int	core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
69e80ac6c4SAndy Grover 		u64, bool, struct se_node_acl *, struct se_portal_group *);
7003a68b44SAndy Grover void	core_disable_device_list_for_node(struct se_lun *, struct se_dev_entry *,
7129a05deeSNicholas Bellinger 		struct se_node_acl *, struct se_portal_group *);
7229a05deeSNicholas Bellinger void	core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *);
73e26d99aeSChristoph Hellwig int	core_dev_add_lun(struct se_portal_group *, struct se_device *,
746bb82612SNicholas Bellinger 		struct se_lun *lun);
756bb82612SNicholas Bellinger void	core_dev_del_lun(struct se_portal_group *, struct se_lun *);
76cd9d7cbaSAndy Grover struct se_lun_acl *core_dev_init_initiator_node_lun_acl(struct se_portal_group *,
77e26d99aeSChristoph Hellwig 		struct se_node_acl *, u64, int *);
78f2d30680SHannes Reinecke int	core_dev_add_initiator_node_lun_acl(struct se_portal_group *,
79e26d99aeSChristoph Hellwig 		struct se_lun_acl *, struct se_lun *lun, bool);
8003a68b44SAndy Grover int	core_dev_del_initiator_node_lun_acl(struct se_lun *,
81adf653f9SChristoph Hellwig 		struct se_lun_acl *);
82adf653f9SChristoph Hellwig void	core_dev_free_initiator_node_lun_acl(struct se_portal_group *,
83e26d99aeSChristoph Hellwig 		struct se_lun_acl *lacl);
84e26d99aeSChristoph Hellwig int	core_dev_setup_virtual_lun0(void);
85e26d99aeSChristoph Hellwig void	core_dev_release_virtual_lun0(void);
86e26d99aeSChristoph Hellwig struct se_device *target_alloc_device(struct se_hba *hba, const char *name);
870fd97ccfSChristoph Hellwig int	target_configure_device(struct se_device *dev);
880fd97ccfSChristoph Hellwig void	target_free_device(struct se_device *);
890fd97ccfSChristoph Hellwig int	target_for_each_device(int (*fn)(struct se_device *dev, void *data),
90b1943fd4SMike Christie 			       void *data);
91b1943fd4SMike Christie void	target_dev_ua_allocate(struct se_device *dev, u8 asc, u8 ascq);
92*6290e23fSDmitry Bogdanov 
93e26d99aeSChristoph Hellwig /* target_core_configfs.c */
940a06d430SChristoph Hellwig extern struct configfs_item_operations target_core_dev_item_ops;
95c48e5594SBart Van Assche void	target_setup_backend_cits(struct target_backend *);
960a06d430SChristoph Hellwig 
970a06d430SChristoph Hellwig /* target_core_fabric_configfs.c */
982eafd729SChristoph Hellwig int	target_fabric_setup_cits(struct target_fabric_configfs *);
992eafd729SChristoph Hellwig 
1002eafd729SChristoph Hellwig /* target_core_fabric_lib.c */
1012650d71eSChristoph Hellwig int	target_get_pr_transport_id_len(struct se_node_acl *nacl,
1022650d71eSChristoph Hellwig 		struct t10_pr_registration *pr_reg, int *format_code);
1032650d71eSChristoph Hellwig int	target_get_pr_transport_id(struct se_node_acl *nacl,
1042650d71eSChristoph Hellwig 		struct t10_pr_registration *pr_reg, int *format_code,
1052650d71eSChristoph Hellwig 		unsigned char *buf);
1062650d71eSChristoph Hellwig const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
1072650d71eSChristoph Hellwig 		char *buf, u32 *out_tid_len, char **port_nexus_ptr);
108094bb5d7SRasmus Villemoes 
1092650d71eSChristoph Hellwig /* target_core_hba.c */
110e26d99aeSChristoph Hellwig struct se_hba *core_alloc_hba(const char *, u32, u32);
111e26d99aeSChristoph Hellwig int	core_delete_hba(struct se_hba *);
112e26d99aeSChristoph Hellwig 
113e26d99aeSChristoph Hellwig /* target_core_tmr.c */
114e26d99aeSChristoph Hellwig void	core_tmr_abort_task(struct se_device *, struct se_tmr_req *,
1153d28934aSNicholas Bellinger 			struct se_session *);
1163d28934aSNicholas Bellinger int	core_tmr_lun_reset(struct se_device *, struct se_tmr_req *,
117e26d99aeSChristoph Hellwig 		struct list_head *, struct se_cmd *);
118e26d99aeSChristoph Hellwig 
119e26d99aeSChristoph Hellwig /* target_core_tpg.c */
120e26d99aeSChristoph Hellwig extern struct se_device *g_lun0_dev;
121e26d99aeSChristoph Hellwig 
122e26d99aeSChristoph Hellwig struct se_node_acl *__core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
123e26d99aeSChristoph Hellwig 		const char *);
124e26d99aeSChristoph Hellwig void	core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *,
125df9766caSNicholas Bellinger 				  struct se_lun *);
126df9766caSNicholas Bellinger void	core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *);
127e26d99aeSChristoph Hellwig struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64);
128f2d30680SHannes Reinecke int	core_tpg_add_lun(struct se_portal_group *, struct se_lun *,
129d344f8a1SAndy Grover 		bool, struct se_device *);
13003a68b44SAndy Grover void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
131cd9d7cbaSAndy Grover struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg,
132c7d6a803SChristoph Hellwig 		const char *initiatorname);
133c7d6a803SChristoph Hellwig void core_tpg_del_initiator_node_acl(struct se_node_acl *acl);
134c7d6a803SChristoph Hellwig int target_tpg_enable(struct se_portal_group *se_tpg);
135e26d99aeSChristoph Hellwig int target_tpg_disable(struct se_portal_group *se_tpg);
136e26d99aeSChristoph Hellwig 
137e26d99aeSChristoph Hellwig /* target_core_transport.c */
138e26d99aeSChristoph Hellwig int	init_se_kmem_caches(void);
139e26d99aeSChristoph Hellwig void	release_se_kmem_caches(void);
140e26d99aeSChristoph Hellwig u32	scsi_get_new_index(scsi_index_t);
141e26d99aeSChristoph Hellwig void	transport_subsystem_check_init(void);
142e26d99aeSChristoph Hellwig unsigned char *transport_dump_cmd_direction(struct se_cmd *);
143e26d99aeSChristoph Hellwig void	transport_dump_dev_state(struct se_device *, char *, int *);
144e26d99aeSChristoph Hellwig void	transport_dump_dev_info(struct se_device *, struct se_lun *,
145e26d99aeSChristoph Hellwig 		unsigned long long, char *, int *);
146e26d99aeSChristoph Hellwig void	transport_dump_vpd_proto_id(struct t10_vpd *, unsigned char *, int);
147e26d99aeSChristoph Hellwig int	transport_dump_vpd_assoc(struct t10_vpd *, unsigned char *, int);
148e26d99aeSChristoph Hellwig int	transport_dump_vpd_ident_type(struct t10_vpd *, unsigned char *, int);
149b3eeea66SBart Van Assche int	transport_dump_vpd_ident(struct t10_vpd *, unsigned char *, int);
150de103c93SChristoph Hellwig void	transport_clear_lun_ref(struct se_lun *);
1510fd97ccfSChristoph Hellwig sense_reason_t	target_cmd_size_check(struct se_cmd *cmd, unsigned int size);
152ed1227e0SMike Christie void	target_qf_do_work(struct work_struct *work);
153814e5b45SChristoph Hellwig void	target_do_delayed_work(struct work_struct *work);
154814e5b45SChristoph Hellwig bool	target_check_wce(struct se_device *dev);
155dff0ca9eSNicholas Bellinger bool	target_check_fua(struct se_device *dev);
156eb44ce8cSMike Christie void	__target_execute_cmd(struct se_cmd *, bool);
157e26d99aeSChristoph Hellwig void	target_queued_submit_work(struct work_struct *work);
158e26d99aeSChristoph Hellwig 
1590fd97ccfSChristoph Hellwig /* target_core_stat.c */
160e26d99aeSChristoph Hellwig void	target_stat_setup_dev_default_groups(struct se_device *);
161e26d99aeSChristoph Hellwig void	target_stat_setup_port_default_groups(struct se_lun *);
162e26d99aeSChristoph Hellwig void	target_stat_setup_mappedlun_default_groups(struct se_lun_acl *);
163adf653f9SChristoph Hellwig 
164adf653f9SChristoph Hellwig /* target_core_xcopy.c */
165adf653f9SChristoph Hellwig extern struct se_portal_group xcopy_pt_tpg;
166a96e9783SLee Duncan 
167a96e9783SLee Duncan /* target_core_configfs.c */
168a96e9783SLee Duncan #define DB_ROOT_LEN		4096
16978a6295cSLee Duncan #define	DB_ROOT_DEFAULT		"/var/target"
170a96e9783SLee Duncan #define	DB_ROOT_PREFERRED	"/etc/target"
171a96e9783SLee Duncan 
172a96e9783SLee Duncan extern char db_root[];
173e26d99aeSChristoph Hellwig 
174 #endif /* TARGET_CORE_INTERNAL_H */
175