xref: /illumos-gate/usr/src/lib/storage/libg_fc/common/hdrs/g_state.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_G_STATE_H
27 #define	_G_STATE_H
28 
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * Include any headers you depend on.
36  */
37 
38 /*
39  * I18N message number ranges
40  *  This file: 19000 - 19499
41  *  Shared common messages: 1 - 1999
42  */
43 
44 #include	<libdevice.h>
45 #include	<sys/fibre-channel/fcio.h>
46 #include	<sys/sunmdi.h>
47 /*
48  * sys/fc4/fcio.h includes sys/fc4/fcal_linkapp.h.  The following #define
49  * keeps from actually including the contents of sys/fc4/fcal_linkapp.h
50  * since that file contains the same structure definitions as sys/fc4/fcio.h.
51  */
52 #define	_SYS_FC4_FCAL_LINKAPP_H
53 #include	<sys/fc4/fcio.h>
54 #include	<sys/devctl.h>
55 #include	<g_scsi.h>
56 #include	<sys/scsi/generic/commands.h>
57 #include	<libnvpair.h>
58 #include	<libdevinfo.h>
59 
60 #define	MAXPATHSTATE	5
61 
62 #include 	<gfc.h>
63 
64 /* hotplug defines */
65 #define	SENA		1
66 #define	NON_SENA	0
67 /* format parameters to dump() */
68 #define	HEX_ONLY	0	/* Print Hex only */
69 #define	HEX_ASCII	1	/* Print Hex and Ascii */
70 /* Persistent Reservation */
71 #define	ACTION_READ_KEYS	0x00
72 #define	ACTION_READ_RESERV	0x01
73 #define	ACTION_REGISTER		0x00
74 #define	ACTION_RESERVE		0x01
75 #define	ACTION_RELEASE		0x02
76 #define	ACTION_CLEAR		0x03
77 #define	ACTION_PREEMPT		0x04
78 #define	ACTION_PREEMPT_CLR	0x05
79 
80 /* Some constants for fabric/public loops */
81 #define	AREA_DOMAIN_ID		0x00FFFF00
82 
83 /* Max number of retries */
84 #define	RETRY_FCIO_IOCTL	360
85 #define	RETRY_FCP_IOCTL		360
86 #define	RETRY_OBJECT_OPEN	5
87 #define	RETRY_PATHLIST		1
88 
89 /* Wait times in microseconds */
90 #define	WAIT_FCIO_IOCTL		250000 /* 1/4 of a second */
91 #define	WAIT_FCP_IOCTL		250000 /* 1/4 of a second */
92 #define	WAIT_OBJECT_OPEN	10000  /* 1/100 of a sec. */
93 
94 /* Defines for VS inq_port field on standard page (bit 5 Byte 6 */
95 #define	PATH_PRIMARY		0x0
96 #define	PATH_FAILOVER		0x1
97 
98 /*
99  * Macro for deallocating memory pointed by dev_addr pointer
100  * of gfc_map_t structure.
101  * It is defined here to make available at any place from
102  * luxadm, liba5k and libg_fc.
103  *
104  * Note: The macro will try to free any non-NULL dev_addr.
105  *       So, dev_addr ptr needs to be initialized to NULL.
106  *
107  *       map.dev_addr = (gfc_port_dev_info_t *)NULL
108  *       map->dev_addr = (gfc_port_dev_info_t *)NULL.
109  */
110 #define	FREE_DEV_ADDR(D_PTR)	if (D_PTR != NULL) {\
111 					free((void *)D_PTR);\
112 					D_PTR = (gfc_port_dev_info_t *)NULL;\
113 				}
114 
115 /* Constants and macros used by the g_get_path_type() function */
116 #define	SLASH		"/"
117 #define	DEV_PREFIX	"/devices/"	/* base pathname for devfs names */
118 #define	DEV_PREFIX_LEN	9		/* Length of DEV_PREFIX string */
119 					/* Can do a strlen and generalize */
120 					/* but this is is easier */
121 #define	DEVICES_DIR	"/devices"
122 
123 /* Defines for minor names used to append to devfs paths */
124 #define	SSD_MINOR_NAME		":c,raw"
125 #define	ST_MINOR_NAME		":n"
126 
127 /* Defines for ssd driver name passed to root tree search routines */
128 #define	SSD_DRVR_NAME	"ssd"
129 #define	ST_DRVR_NAME	"st"
130 
131 /*
132  * Property names
133  */
134 #define	PORT_WWN_PROP	"port-wwn"
135 #define	NODE_WWN_PROP	"node-wwn"
136 #define	LUN_GUID_PROP	"client-guid"
137 #define	LUN_PROP	"lun"
138 
139 typedef struct	read_keys_struct {
140 	int		rk_generation;
141 	int		rk_length;
142 	int		rk_key[256];
143 } Read_keys;
144 
145 typedef struct	read_reserv_struct {
146 	int		rr_generation;
147 	int		rr_length;
148 } Read_reserv;
149 
150 /*
151  * mplist structure typedef to support multipath
152  */
153 typedef struct mplist_struct {
154 	char *devpath;
155 	struct mplist_struct *next;
156 } Mplist;
157 
158 /* wwn_list_found to track previous calls to g_get_wwn */
159 typedef struct wwn_list_found_struct {
160 	uchar_t	node_wwn[WWN_SIZE];
161 	uchar_t	port_wwn[WWN_SIZE];
162 	struct	wwn_list_found_struct	*wwn_next;
163 } WWN_list_found;
164 
165 /* Function prototyes defined for libg_fc modules */
166 /* genf.c */
167 extern void	*g_zalloc(int);
168 extern char	*g_alloc_string(char *);
169 extern void	g_destroy_data(void *);
170 extern void	g_dump(char *, uchar_t *, int, int);
171 extern int	g_object_open(char *, int);
172 extern char	*g_scsi_find_command_name(int);
173 extern void	g_scsi_printerr(struct uscsi_cmd *,
174 		struct scsi_extended_sense *, int, char msg_string[], char *);
175 extern int	g_get_machineArch(int *);
176 extern boolean_t g_enclDiskChk(char *, char *);
177 
178 /* hot.c */
179 extern void	g_ll_to_str(uchar_t *, char *);
180 extern void	g_free_hotplug_dlist(struct hotplug_disk_list **);
181 
182 /* map.c */
183 extern int	g_string_to_wwn(uchar_t *, uchar_t *);
184 extern int	g_get_perf_statistics(char *, uchar_t *);
185 extern int	g_get_port_multipath(char *, struct dlist **, int);
186 extern int	g_device_in_map(gfc_map_t *, int);
187 extern int	g_start(char *);
188 extern int	g_stop(char *, int);
189 extern int	g_reserve(char *);
190 extern int	g_release(char *);
191 extern int	g_issue_fcio_ioctl(int, fcio_t *, int);
192 extern void	g_sort_wwn_list(struct wwn_list_struct **);
193 extern void	g_free_wwn_list_found(struct wwn_list_found_struct **);
194 
195 /* cmd.c */
196 extern int	cmd(int, struct uscsi_cmd *, int);
197 
198 /* io.c */
199 extern int	g_scsi_persistent_reserve_in_cmd(int, uchar_t *, int, uchar_t);
200 extern int	g_scsi_send_diag_cmd(int, uchar_t *, int);
201 extern int	g_scsi_rec_diag_cmd(int, uchar_t *, int, uchar_t);
202 extern int	g_scsi_writebuffer_cmd(int, int, uchar_t *, int, int, int);
203 extern int	g_scsi_readbuffer_cmd(int, uchar_t *, int, int);
204 extern int	g_scsi_inquiry_cmd(int, uchar_t *, int);
205 extern int	g_scsi_log_sense_cmd(int, uchar_t *, int, uchar_t);
206 extern int	g_scsi_mode_select_cmd(int, uchar_t *, int, uchar_t);
207 extern int	g_scsi_mode_sense_cmd(int, uchar_t *, int, uchar_t, uchar_t);
208 extern int	g_scsi_read_capacity_cmd(int, uchar_t *, int);
209 extern int	g_scsi_read_capacity_1016_cmd(int, struct scsi_capacity_16 *,
210 			int);
211 extern int	g_scsi_release_cmd(int);
212 extern int	g_scsi_reserve_cmd(int);
213 extern int	g_scsi_start_cmd(int);
214 extern int	g_scsi_stop_cmd(int, int);
215 extern int	g_scsi_tur(int);
216 extern int	g_scsi_reset(int);
217 extern int	g_devid_get(char *, ddi_devid_t *, di_node_t root,
218 			const char *);
219 
220 /* mpath.c */
221 extern int	g_get_lun_str(char *, char *, int);
222 extern int	g_get_lun_number(char *);
223 extern int	g_get_pathcount(char *);
224 extern int	g_devices_get_all(struct wwn_list_struct **);
225 
226 #ifdef	__cplusplus
227 }
228 #endif
229 
230 #endif	/* _G_STATE_H */
231