1 #ifndef TARGET_CORE_ALUA_H
2 #define TARGET_CORE_ALUA_H
3 
4 #include <target/target_core_base.h>
5 
6 /*
7  * INQUIRY response data, TPGS Field
8  *
9  * from spc4r17 section 6.4.2 Table 135
10  */
11 #define TPGS_NO_ALUA				0x00
12 #define TPGS_IMPLICIT_ALUA			0x10
13 #define TPGS_EXPLICIT_ALUA			0x20
14 
15 /*
16  * ASYMMETRIC ACCESS STATE field
17  *
18  * from spc4r36j section 6.37 Table 307
19  */
20 #define ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED	0x0
21 #define ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED	0x1
22 #define ALUA_ACCESS_STATE_STANDBY		0x2
23 #define ALUA_ACCESS_STATE_UNAVAILABLE		0x3
24 #define ALUA_ACCESS_STATE_LBA_DEPENDENT		0x4
25 #define ALUA_ACCESS_STATE_OFFLINE		0xe
26 #define ALUA_ACCESS_STATE_TRANSITION		0xf
27 
28 /*
29  * from spc4r36j section 6.37 Table 306
30  */
31 #define ALUA_T_SUP		0x80
32 #define ALUA_O_SUP		0x40
33 #define ALUA_LBD_SUP		0x10
34 #define ALUA_U_SUP		0x08
35 #define ALUA_S_SUP		0x04
36 #define ALUA_AN_SUP		0x02
37 #define ALUA_AO_SUP		0x01
38 
39 /*
40  * REPORT_TARGET_PORT_GROUP STATUS CODE
41  *
42  * from spc4r17 section 6.27 Table 246
43  */
44 #define ALUA_STATUS_NONE				0x00
45 #define ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG		0x01
46 #define ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA		0x02
47 
48 /*
49  * From spc4r17, Table D.1: ASC and ASCQ Assignement
50  */
51 #define ASCQ_04H_ALUA_STATE_TRANSITION			0x0a
52 #define ASCQ_04H_ALUA_TG_PT_STANDBY			0x0b
53 #define ASCQ_04H_ALUA_TG_PT_UNAVAILABLE			0x0c
54 #define ASCQ_04H_ALUA_OFFLINE				0x12
55 
56 /*
57  * Used as the default for Active/NonOptimized delay (in milliseconds)
58  * This can also be changed via configfs on a per target port group basis..
59  */
60 #define ALUA_DEFAULT_NONOP_DELAY_MSECS			100
61 #define ALUA_MAX_NONOP_DELAY_MSECS			10000 /* 10 seconds */
62 /*
63  * Used for implicit and explicit ALUA transitional delay, that is disabled
64  * by default, and is intended to be used for debugging client side ALUA code.
65  */
66 #define ALUA_DEFAULT_TRANS_DELAY_MSECS			0
67 #define ALUA_MAX_TRANS_DELAY_MSECS			30000 /* 30 seconds */
68 /*
69  * Used for the recommended application client implicit transition timeout
70  * in seconds, returned by the REPORT_TARGET_PORT_GROUPS w/ extended header.
71  */
72 #define ALUA_DEFAULT_IMPLICIT_TRANS_SECS			0
73 #define ALUA_MAX_IMPLICIT_TRANS_SECS			255
74 /*
75  * Used by core_alua_update_tpg_primary_metadata() and
76  * core_alua_update_tpg_secondary_metadata()
77  */
78 #define ALUA_METADATA_PATH_LEN				512
79 /*
80  * Used by core_alua_update_tpg_secondary_metadata()
81  */
82 #define ALUA_SECONDARY_METADATA_WWN_LEN			256
83 
84 /* Used by core_alua_update_tpg_(primary,secondary)_metadata */
85 #define ALUA_MD_BUF_LEN					1024
86 
87 extern struct kmem_cache *t10_alua_lu_gp_cache;
88 extern struct kmem_cache *t10_alua_lu_gp_mem_cache;
89 extern struct kmem_cache *t10_alua_tg_pt_gp_cache;
90 extern struct kmem_cache *t10_alua_lba_map_cache;
91 extern struct kmem_cache *t10_alua_lba_map_mem_cache;
92 
93 extern sense_reason_t target_emulate_report_target_port_groups(struct se_cmd *);
94 extern sense_reason_t target_emulate_set_target_port_groups(struct se_cmd *);
95 extern sense_reason_t target_emulate_report_referrals(struct se_cmd *);
96 extern int core_alua_check_nonop_delay(struct se_cmd *);
97 extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *,
98 				struct se_device *, struct se_lun *,
99 				struct se_node_acl *, int, int);
100 extern char *core_alua_dump_status(int);
101 extern struct t10_alua_lba_map *core_alua_allocate_lba_map(
102 				struct list_head *, u64, u64);
103 extern int core_alua_allocate_lba_map_mem(struct t10_alua_lba_map *, int, int);
104 extern void core_alua_free_lba_map(struct list_head *);
105 extern void core_alua_set_lba_map(struct se_device *, struct list_head *,
106 				int, int);
107 extern struct t10_alua_lu_gp *core_alua_allocate_lu_gp(const char *, int);
108 extern int core_alua_set_lu_gp_id(struct t10_alua_lu_gp *, u16);
109 extern void core_alua_free_lu_gp(struct t10_alua_lu_gp *);
110 extern void core_alua_free_lu_gp_mem(struct se_device *);
111 extern struct t10_alua_lu_gp *core_alua_get_lu_gp_by_name(const char *);
112 extern void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp *);
113 extern void __core_alua_attach_lu_gp_mem(struct t10_alua_lu_gp_member *,
114 					struct t10_alua_lu_gp *);
115 extern void __core_alua_drop_lu_gp_mem(struct t10_alua_lu_gp_member *,
116 					struct t10_alua_lu_gp *);
117 extern void core_alua_drop_lu_gp_dev(struct se_device *);
118 extern struct t10_alua_tg_pt_gp *core_alua_allocate_tg_pt_gp(
119 			struct se_device *, const char *, int);
120 extern int core_alua_set_tg_pt_gp_id(struct t10_alua_tg_pt_gp *, u16);
121 extern void core_alua_free_tg_pt_gp(struct t10_alua_tg_pt_gp *);
122 extern void target_detach_tg_pt_gp(struct se_lun *);
123 extern void target_attach_tg_pt_gp(struct se_lun *, struct t10_alua_tg_pt_gp *);
124 extern ssize_t core_alua_show_tg_pt_gp_info(struct se_lun *, char *);
125 extern ssize_t core_alua_store_tg_pt_gp_info(struct se_lun *, const char *,
126 						size_t);
127 extern ssize_t core_alua_show_access_type(struct t10_alua_tg_pt_gp *, char *);
128 extern ssize_t core_alua_store_access_type(struct t10_alua_tg_pt_gp *,
129 					const char *, size_t);
130 extern ssize_t core_alua_show_nonop_delay_msecs(struct t10_alua_tg_pt_gp *,
131 						char *);
132 extern ssize_t core_alua_store_nonop_delay_msecs(struct t10_alua_tg_pt_gp *,
133 					const char *, size_t);
134 extern ssize_t core_alua_show_trans_delay_msecs(struct t10_alua_tg_pt_gp *,
135 					char *);
136 extern ssize_t core_alua_store_trans_delay_msecs(struct t10_alua_tg_pt_gp *,
137 					const char *, size_t);
138 extern ssize_t core_alua_show_implicit_trans_secs(struct t10_alua_tg_pt_gp *,
139 					char *);
140 extern ssize_t core_alua_store_implicit_trans_secs(struct t10_alua_tg_pt_gp *,
141 					const char *, size_t);
142 extern ssize_t core_alua_show_preferred_bit(struct t10_alua_tg_pt_gp *,
143 					char *);
144 extern ssize_t core_alua_store_preferred_bit(struct t10_alua_tg_pt_gp *,
145 					const char *, size_t);
146 extern ssize_t core_alua_show_offline_bit(struct se_lun *, char *);
147 extern ssize_t core_alua_store_offline_bit(struct se_lun *, const char *,
148 					size_t);
149 extern ssize_t core_alua_show_secondary_status(struct se_lun *, char *);
150 extern ssize_t core_alua_store_secondary_status(struct se_lun *,
151 					const char *, size_t);
152 extern ssize_t core_alua_show_secondary_write_metadata(struct se_lun *,
153 					char *);
154 extern ssize_t core_alua_store_secondary_write_metadata(struct se_lun *,
155 					const char *, size_t);
156 extern int core_setup_alua(struct se_device *);
157 extern sense_reason_t target_alua_state_check(struct se_cmd *cmd);
158 
159 #endif /* TARGET_CORE_ALUA_H */
160