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