xref: /illumos-gate/usr/src/lib/cfgadm_plugins/sata/common/cfga_sata.h (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
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 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _CFGA_SATA_H
28 #define	_CFGA_SATA_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdlib.h>
37 #include <strings.h>
38 #include <fcntl.h>
39 #include <ctype.h>
40 #include <unistd.h>
41 #include <libintl.h>
42 #include <libdevice.h>
43 #include <sys/varargs.h>
44 
45 #include <sys/sata/sata_cfgadm.h>
46 
47 #include <libdevinfo.h>
48 #include <libdevice.h>
49 #include <librcm.h>
50 #include <synch.h>
51 #include <thread.h>
52 #include <assert.h>
53 
54 #define	CFGA_PLUGIN_LIB
55 #include <config_admin.h>
56 
57 /*
58  * Debug stuff
59  */
60 #ifdef	DEBUG
61 #define	DPRINTF printf
62 #else
63 #define	DPRINTF 0 &&
64 #endif /* DEBUG */
65 
66 typedef enum {
67 	CFGA_SATA_TERMINATE = 0,
68 	CFGA_SATA_CONTINUE
69 } sata_cfga_recur_t;
70 
71 /* for walking links */
72 typedef struct walk_link {
73 	char *path;
74 	char len;
75 	char **linkpp;
76 } walk_link_t;
77 
78 #define	MATCH_MINOR_NAME	1
79 
80 /* Misc text strings */
81 #define	CFGA_DEV_DIR			"/dev/cfg"
82 #define	MINOR_SEP 			":"
83 #define	DYN_SEP				"::"
84 #define	PORT				"port"
85 #define	PORT_SEPARATOR			"."
86 #define	SATA				"sata"
87 #define	CFGA_DEVCTL_NODE  		":devctl"
88 #define	SATA_CFGADM_DEFAULT_AP_TYPE	"unknown"
89 #define	SLICE				"s"
90 #define	PARTITION			"p"
91 #define	PATH_SEP 			"/"
92 
93 /* these set of defines are -lav listing */
94 #define	SATA_UNDEF_STR			"<undef>"
95 #define	SATA_NO_CFG_STR			"<no cfg str descr>"
96 
97 /* -x commands */
98 #define	SATA_RESET_ALL			"sata_reset_all"
99 #define	SATA_RESET_PORT			"sata_reset_port"
100 #define	SATA_RESET_DEVICE		"sata_reset_device"
101 #define	SATA_PORT_DEACTIVATE		"sata_port_deactivate"
102 #define	SATA_PORT_ACTIVATE		"sata_port_activate"
103 #define	SATA_PORT_SELF_TEST		"sata_port_self_test"
104 
105 /* -t command */
106 #define	SATA_CNTRL_SELF_TEST		"sata_cntrl_self_test"
107 
108 /* for confirm operation */
109 #define	SATA_CONFIRM_DEVICE	"the device at: "
110 #define	SATA_CONFIRM_DEVICE_SUSPEND \
111 	"This operation will suspend activity on the SATA device\nContinue"
112 #define	SATA_CONFIRM_DEVICE_ABORT \
113 	"This operation will arbitrarily abort all commands " \
114 	"on SATA device\nContinue"
115 #define	SATA_CONFIRM_CONTROLLER  "the controller: "
116 #define	SATA_CONFIRM_CONTROLLER_ABORT \
117 	"This operation will arbitrarirly abort all commands " \
118 	"on the SATA controller\nContinue"
119 #define	SATA_CONFIRM_PORT	"the port: "
120 #define	SATA_CONFIRM_PORT_DISABLE \
121 	"This operation will disable activity on the SATA port\nContinue"
122 #define	SATA_CONFIRM_PORT_ENABLE \
123 	"This operation will enable activity on the SATA port\nContinue"
124 
125 #define	S_FREE(x)		(((x) != NULL) ? \
126 				(free(x), (x) = NULL) : (void *)0)
127 
128 #define	GET_DYN(a)		(((a) != NULL) ? \
129 				strstr((a), DYN_SEP) : (void *)0)
130 
131 typedef struct sata_apid {
132 	char		*hba_phys;
133 	char		*dyncomp;
134 	char		*path;
135 	uint_t		flags;
136 } sata_apid_t;
137 
138 
139 /* Messages */
140 
141 typedef struct msgcvt {
142 	int		intl;		/* Flag: if 1, internationalize */
143 	cfga_err_t	cfga_err;	/* Error code libcfgadm understands */
144 	const char	*msgstr;
145 } msgcvt_t;
146 
147 #define	NO_CVT	0
148 #define	CVT	1
149 
150 #define	MSG_TBL_SZ(table)	(sizeof ((table)) / sizeof (msgcvt_t))
151 
152 typedef enum {
153 	SATA_CFGA_ERR = -2,
154 	SATA_CFGA_LIB_ERR,
155 	SATA_CFGA_OK,
156 	SATA_CFGA_BUSY,
157 	SATA_CFGA_NO_REC
158 } sata_cfga_ret_t;
159 
160 /* Messages */
161 
162 
163 /* Error message ids (and indices into sata_error_msgs) */
164 typedef enum {
165 	CFGA_SATA_OK = 0,
166 	CFGA_SATA_NACK,
167 	CFGA_SATA_DEVICE_UNCONFIGURED,
168 	CFGA_SATA_UNKNOWN,
169 	CFGA_SATA_INTERNAL_ERROR,
170 	CFGA_SATA_DATA_ERROR,
171 	CFGA_SATA_OPTIONS,
172 	CFGA_SATA_HWOPNOTSUPP,
173 	CFGA_SATA_DYNAMIC_AP,
174 	CFGA_SATA_AP,
175 	CFGA_SATA_PORT,
176 	CFGA_SATA_DEVCTL,
177 	CFGA_SATA_DEV_CONFIGURE,
178 	CFGA_SATA_DEV_UNCONFIGURE,
179 	CFGA_SATA_DISCONNECTED,
180 	CFGA_SATA_NOT_CONNECTED,
181 	CFGA_SATA_NOT_CONFIGURED,
182 	CFGA_SATA_ALREADY_CONNECTED,
183 	CFGA_SATA_ALREADY_CONFIGURED,
184 	CFGA_SATA_INVALID_DEVNAME,
185 	CFGA_SATA_OPEN,
186 	CFGA_SATA_IOCTL,
187 	CFGA_SATA_BUSY,
188 	CFGA_SATA_ALLOC_FAIL,
189 	CFGA_SATA_OPNOTSUPP,
190 	CFGA_SATA_DEVLINK,
191 	CFGA_SATA_STATE,
192 	CFGA_SATA_PRIV,
193 	CFGA_SATA_NVLIST,
194 	CFGA_SATA_ZEROLEN,
195 
196 	/* RCM Errors */
197 	CFGA_SATA_RCM_HANDLE,
198 	CFGA_SATA_RCM_ONLINE,
199 	CFGA_SATA_RCM_OFFLINE,
200 	CFGA_SATA_RCM_INFO
201 
202 } cfga_sata_ret_t;
203 
204 /*
205  * Given an error msg index, look up the associated string, and
206  * convert it to the current locale if required.
207  */
208 #define	ERR_STR(msg_idx) \
209 	(get_msg((msg_idx), sata_msgs, MSG_TBL_SZ(sata_msgs)))
210 
211 /* Prototypes */
212 
213 cfga_err_t	sata_err_msg(char **, cfga_sata_ret_t, const char *, int);
214 cfga_sata_ret_t	sata_rcm_offline(const char *, char **, char *, cfga_flags_t);
215 cfga_sata_ret_t sata_rcm_online(const char *, char **, char *, cfga_flags_t);
216 cfga_sata_ret_t sata_rcm_remove(const char *, char **, char *, cfga_flags_t);
217 
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif	/* _CFGA_SATA_H */
224