xref: /titanic_51/usr/src/uts/common/io/comstar/stmf/lun_map.h (revision 63ed874a56e20df7e4ec98ba42582352d87386c5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 #ifndef	_LUN_MAP_H
26 #define	_LUN_MAP_H
27 
28 #include <sys/stmf_defines.h>
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 typedef struct stmf_lun_map {
35 	uint32_t	lm_nluns;
36 	uint32_t	lm_nentries;
37 	void		**lm_plus; /* this can be lun or view entry */
38 } stmf_lun_map_t;
39 
40 struct stmf_itl_data;
41 
42 typedef struct stmf_lun_map_ent {
43 	struct stmf_lu		*ent_lu;
44 	struct stmf_itl_data	*ent_itl_datap;
45 } stmf_lun_map_ent_t;
46 
47 void stmf_view_init();
48 void stmf_view_clear_config();
49 stmf_status_t stmf_session_create_lun_map(stmf_i_local_port_t *ilport,
50 		stmf_i_scsi_session_t *iss);
51 stmf_status_t stmf_session_destroy_lun_map(stmf_i_local_port_t *ilport,
52 		stmf_i_scsi_session_t *iss);
53 stmf_xfer_data_t *stmf_session_prepare_report_lun_data(stmf_lun_map_t *sm);
54 void stmf_add_lu_to_active_sessions(stmf_lu_t *lu);
55 void stmf_session_lu_unmapall(stmf_lu_t *lu);
56 void *stmf_get_ent_from_map(stmf_lun_map_t *sm, uint16_t lun_num);
57 
58 
59 /*
60  * Common struct used to maintain an Identifer's data. That Identifier
61  * can be a Host group, Target group or LU GUID data. Note that a LU is
62  * different from LU GUID data because either can be there without
63  * its counterpart being present in the system.
64  * id_impl_specific pointer to:
65  * case LUID, a list of stmf_view_entry
66  * case initiator group, a list of initiators
67  * case target group, a list of targets
68  * id_pt_to_object pointer to stmf_i_lu_t instance for LU.
69  */
70 typedef struct stmf_id_data {
71 	struct stmf_id_data		*id_next;
72 	struct stmf_id_data		*id_prev;
73 	uint32_t			id_refcnt;
74 	uint16_t			id_type;
75 	uint16_t			id_data_size;
76 	uint8_t				*id_data;
77 	uint32_t			id_total_alloc_size;
78 	uint32_t			id_rsvd;
79 	void				*id_pt_to_object;
80 	void				*id_impl_specific;
81 } stmf_id_data_t;
82 
83 typedef enum {
84 	STMF_ID_TYPE_HOST,
85 	STMF_ID_TYPE_TARGET,
86 	STMF_ID_TYPE_LU_GUID,
87 	STMF_ID_TYPE_HOST_GROUP,
88 	STMF_ID_TYPE_TARGET_GROUP
89 } stmf_id_type_t;
90 
91 typedef struct stmf_id_list {
92 	stmf_id_data_t		*idl_head;
93 	stmf_id_data_t		*idl_tail;
94 	uint32_t		id_count;
95 } stmf_id_list_t;
96 
97 typedef struct stmf_view_entry {
98 	struct stmf_view_entry	*ve_next;
99 	struct stmf_view_entry	*ve_prev;
100 	uint32_t		ve_id;
101 	stmf_id_data_t		*ve_hg;
102 	stmf_id_data_t		*ve_tg;
103 	stmf_id_data_t		*ve_luid;
104 	uint8_t			ve_lun[8];
105 } stmf_view_entry_t;
106 
107 /*
108  * Following structs are used as an alternate representation of view entries
109  * in a LU ID.
110  * ver_tg_root--->ver_tg_t    +-> ver_tg_t ....
111  *                   |        |
112  *                  vert_next-+
113  *                   |
114  *                   vert_verh_list --> ver_hg_t  +-> ver_hg_t ....
115  *                                        |       |
116  *                                      verh_next-+
117  *                                        |
118  *                                      verh_ve_map (view entry map for this
119  *                                             target group + host group )
120  */
121 
122 typedef struct ver_hg {
123 	struct ver_hg		*verh_next;
124 	stmf_id_data_t		*verh_hg_ref;	/* ref. to the host group */
125 	stmf_lun_map_t		verh_ve_map;
126 } stmf_ver_hg_t;
127 
128 typedef struct ver_tg {
129 	struct ver_tg		*vert_next;
130 	stmf_id_data_t		*vert_tg_ref;	/* ref to target group */
131 	stmf_ver_hg_t		*vert_verh_list;
132 } stmf_ver_tg_t;
133 
134 /*
135  * flag which define how the merging of maps is to be done.
136  */
137 typedef enum {
138 	MERGE_FLAG_NO_DUPLICATE		= 0x01, /* fail upon duplicate */
139 	MERGE_FLAG_RETURN_NEW_MAP	= 0x02, /* Does not modify dst */
140 	MERGE_FLAG_NONE			= 0
141 } stmf_merge_flags_t;
142 
143 int stmf_add_group_member(uint8_t *grpname, uint16_t grpname_size,
144 		uint8_t	*entry_ident, uint16_t entry_size,
145 		stmf_id_type_t entry_type, uint32_t *err_detail);
146 int stmf_remove_group_member(uint8_t *grpname, uint16_t grpname_size,
147 		uint8_t *entry_ident, uint16_t entry_size,
148 		stmf_id_type_t entry_type, uint32_t *err_detail);
149 int stmf_remove_group(uint8_t *grpname, uint16_t grpname_size,
150 		stmf_id_type_t group_type, uint32_t *err_detail);
151 int stmf_add_group(uint8_t *grpname, uint16_t grpname_size,
152 		stmf_id_type_t group_type, uint32_t *err_detail);
153 int stmf_add_ve(uint8_t *hgname, uint16_t hgname_size, uint8_t *tgname,
154 		uint16_t tgname_size, uint8_t *lu_guid, uint32_t *ve_id,
155 		uint8_t *luNbr, uint32_t *err_detail);
156 int stmf_validate_lun_ve(uint8_t *hgname, uint16_t hgname_size, uint8_t *tgname,
157 		uint16_t tgname_size, uint8_t *luNbr, uint32_t *err_detail);
158 int stmf_remove_ve_by_id(uint8_t *guid, uint32_t veid, uint32_t *err_detail);
159 stmf_id_data_t *stmf_lookup_id(stmf_id_list_t *idlist, uint16_t id_size,
160 		uint8_t *data);
161 stmf_id_data_t *stmf_lookup_group_for_target(uint8_t *ident,
162 		uint16_t ident_size);
163 
164 #ifdef	__cplusplus
165 }
166 #endif
167 
168 #endif /* _LUN_MAP_H */
169