1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef TARGET_CORE_INTERNAL_H
3 #define TARGET_CORE_INTERNAL_H
4 
5 #include <linux/configfs.h>
6 #include <linux/list.h>
7 #include <linux/types.h>
8 #include <target/target_core_base.h>
9 
10 #define TARGET_CORE_NAME_MAX_LEN	64
11 #define TARGET_FABRIC_NAME_SIZE		32
12 
13 struct target_backend {
14 	struct list_head list;
15 
16 	const struct target_backend_ops *ops;
17 
18 	struct config_item_type tb_dev_cit;
19 	struct config_item_type tb_dev_attrib_cit;
20 	struct config_item_type tb_dev_action_cit;
21 	struct config_item_type tb_dev_pr_cit;
22 	struct config_item_type tb_dev_wwn_cit;
23 	struct config_item_type tb_dev_alua_tg_pt_gps_cit;
24 	struct config_item_type tb_dev_stat_cit;
25 };
26 
27 struct target_fabric_configfs {
28 	atomic_t		tf_access_cnt;
29 	struct list_head	tf_list;
30 	struct config_group	tf_group;
31 	struct config_group	tf_disc_group;
32 	const struct target_core_fabric_ops *tf_ops;
33 
34 	struct config_item_type tf_discovery_cit;
35 	struct config_item_type	tf_wwn_cit;
36 	struct config_item_type tf_wwn_fabric_stats_cit;
37 	struct config_item_type tf_tpg_cit;
38 	struct config_item_type tf_tpg_base_cit;
39 	struct config_item_type tf_tpg_lun_cit;
40 	struct config_item_type tf_tpg_port_cit;
41 	struct config_item_type tf_tpg_port_stat_cit;
42 	struct config_item_type tf_tpg_np_cit;
43 	struct config_item_type tf_tpg_np_base_cit;
44 	struct config_item_type tf_tpg_attrib_cit;
45 	struct config_item_type tf_tpg_auth_cit;
46 	struct config_item_type tf_tpg_param_cit;
47 	struct config_item_type tf_tpg_nacl_cit;
48 	struct config_item_type tf_tpg_nacl_base_cit;
49 	struct config_item_type tf_tpg_nacl_attrib_cit;
50 	struct config_item_type tf_tpg_nacl_auth_cit;
51 	struct config_item_type tf_tpg_nacl_param_cit;
52 	struct config_item_type tf_tpg_nacl_stat_cit;
53 	struct config_item_type tf_tpg_mappedlun_cit;
54 	struct config_item_type tf_tpg_mappedlun_stat_cit;
55 };
56 
57 /* target_core_alua.c */
58 extern struct t10_alua_lu_gp *default_lu_gp;
59 
60 /* target_core_device.c */
61 int	core_alloc_rtpi(struct se_lun *lun, struct se_device *dev);
62 struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16);
63 void	target_pr_kref_release(struct kref *);
64 void	core_free_device_list_for_node(struct se_node_acl *,
65 		struct se_portal_group *);
66 void	core_update_device_list_access(u64, bool, struct se_node_acl *);
67 struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u64);
68 int	core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *,
69 		u64, bool, struct se_node_acl *, struct se_portal_group *);
70 void	core_disable_device_list_for_node(struct se_lun *, struct se_dev_entry *,
71 		struct se_node_acl *, struct se_portal_group *);
72 void	core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *);
73 int	core_dev_add_lun(struct se_portal_group *, struct se_device *,
74 		struct se_lun *lun);
75 void	core_dev_del_lun(struct se_portal_group *, struct se_lun *);
76 struct se_lun_acl *core_dev_init_initiator_node_lun_acl(struct se_portal_group *,
77 		struct se_node_acl *, u64, int *);
78 int	core_dev_add_initiator_node_lun_acl(struct se_portal_group *,
79 		struct se_lun_acl *, struct se_lun *lun, bool);
80 int	core_dev_del_initiator_node_lun_acl(struct se_lun *,
81 		struct se_lun_acl *);
82 void	core_dev_free_initiator_node_lun_acl(struct se_portal_group *,
83 		struct se_lun_acl *lacl);
84 int	core_dev_setup_virtual_lun0(void);
85 void	core_dev_release_virtual_lun0(void);
86 struct se_device *target_alloc_device(struct se_hba *hba, const char *name);
87 int	target_configure_device(struct se_device *dev);
88 void	target_free_device(struct se_device *);
89 int	target_for_each_device(int (*fn)(struct se_device *dev, void *data),
90 			       void *data);
91 
92 /* target_core_configfs.c */
93 extern struct configfs_item_operations target_core_dev_item_ops;
94 void	target_setup_backend_cits(struct target_backend *);
95 
96 /* target_core_fabric_configfs.c */
97 int	target_fabric_setup_cits(struct target_fabric_configfs *);
98 
99 /* target_core_fabric_lib.c */
100 int	target_get_pr_transport_id_len(struct se_node_acl *nacl,
101 		struct t10_pr_registration *pr_reg, int *format_code);
102 int	target_get_pr_transport_id(struct se_node_acl *nacl,
103 		struct t10_pr_registration *pr_reg, int *format_code,
104 		unsigned char *buf);
105 const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
106 		char *buf, u32 *out_tid_len, char **port_nexus_ptr);
107 
108 /* target_core_hba.c */
109 struct se_hba *core_alloc_hba(const char *, u32, u32);
110 int	core_delete_hba(struct se_hba *);
111 
112 /* target_core_tmr.c */
113 void	core_tmr_abort_task(struct se_device *, struct se_tmr_req *,
114 			struct se_session *);
115 int	core_tmr_lun_reset(struct se_device *, struct se_tmr_req *,
116 		struct list_head *, struct se_cmd *);
117 
118 /* target_core_tpg.c */
119 extern struct se_device *g_lun0_dev;
120 
121 struct se_node_acl *__core_tpg_get_initiator_node_acl(struct se_portal_group *tpg,
122 		const char *);
123 void	core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *,
124 				  struct se_lun *);
125 void	core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *);
126 struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64);
127 int	core_tpg_add_lun(struct se_portal_group *, struct se_lun *,
128 		bool, struct se_device *);
129 void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
130 struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg,
131 		const char *initiatorname);
132 void core_tpg_del_initiator_node_acl(struct se_node_acl *acl);
133 
134 /* target_core_transport.c */
135 extern struct kmem_cache *se_tmr_req_cache;
136 
137 int	init_se_kmem_caches(void);
138 void	release_se_kmem_caches(void);
139 u32	scsi_get_new_index(scsi_index_t);
140 void	transport_subsystem_check_init(void);
141 int	transport_cmd_finish_abort(struct se_cmd *);
142 unsigned char *transport_dump_cmd_direction(struct se_cmd *);
143 void	transport_dump_dev_state(struct se_device *, char *, int *);
144 void	transport_dump_dev_info(struct se_device *, struct se_lun *,
145 		unsigned long long, char *, int *);
146 void	transport_dump_vpd_proto_id(struct t10_vpd *, unsigned char *, int);
147 int	transport_dump_vpd_assoc(struct t10_vpd *, unsigned char *, int);
148 int	transport_dump_vpd_ident_type(struct t10_vpd *, unsigned char *, int);
149 int	transport_dump_vpd_ident(struct t10_vpd *, unsigned char *, int);
150 void	transport_clear_lun_ref(struct se_lun *);
151 void	transport_send_task_abort(struct se_cmd *);
152 sense_reason_t	target_cmd_size_check(struct se_cmd *cmd, unsigned int size);
153 void	target_qf_do_work(struct work_struct *work);
154 bool	target_check_wce(struct se_device *dev);
155 bool	target_check_fua(struct se_device *dev);
156 void	__target_execute_cmd(struct se_cmd *, bool);
157 
158 /* target_core_stat.c */
159 void	target_stat_setup_dev_default_groups(struct se_device *);
160 void	target_stat_setup_port_default_groups(struct se_lun *);
161 void	target_stat_setup_mappedlun_default_groups(struct se_lun_acl *);
162 
163 /* target_core_xcopy.c */
164 extern struct se_portal_group xcopy_pt_tpg;
165 
166 /* target_core_configfs.c */
167 #define DB_ROOT_LEN		4096
168 #define	DB_ROOT_DEFAULT		"/var/target"
169 #define	DB_ROOT_PREFERRED	"/etc/target"
170 
171 extern char db_root[];
172 
173 #endif /* TARGET_CORE_INTERNAL_H */
174