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