xref: /illumos-gate/usr/src/lib/cfgadm_plugins/ib/common/cfga_ib.h (revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _CFGA_IB_H
28 #define	_CFGA_IB_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 <sys/types32.h>
43 #include <sys/varargs.h>
44 #include <sys/ib/ibnex/ibnex_devctl.h>
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 /*
57  * Debug stuff.
58  */
59 #ifdef	DEBUG
60 #define	DPRINTF	printf
61 #else
62 #define	DPRINTF 0 &&
63 #endif /* DEBUG */
64 
65 
66 /* for walking links */
67 typedef struct walk_link {
68 	char *path;
69 	char len;
70 	char **linkpp;
71 } walk_link_t;
72 
73 
74 /*
75  * Stuff carried over for the routines borrowed from cfgadm/SCSI.
76  */
77 #define	MATCH_MINOR_NAME	1
78 #define	S_FREE(x)	(((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
79 
80 /* Return/error codes */
81 typedef enum {
82 	ICFGA_ERR = -2,
83 	ICFGA_LIB_ERR,
84 	ICFGA_OK,
85 	ICFGA_BUSY,
86 	ICFGA_NO_REC
87 } icfga_ret_t;
88 
89 
90 /* Error Messages */
91 typedef struct {
92 	int		intl;		/* Flag: if 1, internationalize */
93 	cfga_err_t	cfga_err;	/* Error code for libcfgadm */
94 	const char	*msgstr;
95 } msgcvt_t;
96 
97 /* "intl" defines */
98 #define	NO_CVT			0
99 #define	CVT			1
100 
101 #define	MSG_TBL_SZ(table)	(sizeof ((table)) / sizeof (msgcvt_t))
102 
103 
104 /* Error message ids (and indices into ib_error_msgs) "cfga_err values " */
105 typedef enum {
106 	CFGA_IB_OK = 0,			/* Plugin Related Errors */
107 	CFGA_IB_UNKNOWN,
108 	CFGA_IB_INTERNAL_ERR,
109 	CFGA_IB_INVAL_ARG_ERR,
110 	CFGA_IB_OPTIONS_ERR,
111 	CFGA_IB_AP_ERR,
112 	CFGA_IB_DEVCTL_ERR,
113 	CFGA_IB_NOT_CONNECTED,
114 	CFGA_IB_NOT_CONFIGURED,
115 	CFGA_IB_ALREADY_CONNECTED,
116 	CFGA_IB_ALREADY_CONFIGURED,
117 	CFGA_IB_CONFIG_OP_ERR,
118 	CFGA_IB_UNCONFIG_OP_ERR,
119 	CFGA_IB_OPEN_ERR,
120 	CFGA_IB_IOCTL_ERR,
121 	CFGA_IB_BUSY_ERR,
122 	CFGA_IB_ALLOC_FAIL,
123 	CFGA_IB_OPNOTSUPP,
124 	CFGA_IB_INVAL_APID_ERR,
125 	CFGA_IB_DEVLINK_ERR,
126 	CFGA_IB_PRIV_ERR,
127 	CFGA_IB_NVLIST_ERR,
128 	CFGA_IB_HCA_LIST_ERR,
129 	CFGA_IB_HCA_UNCONFIG_ERR,
130 	CFGA_IB_UPD_PKEY_TBLS_ERR,
131 	CFGA_IB_CONFIG_FILE_ERR,
132 	CFGA_IB_LOCK_FILE_ERR,
133 	CFGA_IB_UNLOCK_FILE_ERR,
134 	CFGA_IB_COMM_INVAL_ERR,
135 	CFGA_IB_SVC_INVAL_ERR,
136 	CFGA_IB_SVC_LEN_ERR,
137 	CFGA_IB_SVC_EXISTS_ERR,
138 	CFGA_IB_SVC_NO_EXIST_ERR,
139 	CFGA_IB_UCFG_CLNTS_ERR,
140 	CFGA_IB_INVALID_OP_ERR,
141 
142 	CFGA_IB_RCM_HANDLE_ERR,		/* Plugin's RCM Related Errors */
143 	CFGA_IB_RCM_ONLINE_ERR,
144 	CFGA_IB_RCM_OFFLINE_ERR
145 } cfga_ib_ret_t;
146 
147 
148 /*
149  * Given an error msg index, look up the associated string, and
150  * convert it to the current locale if required.
151  */
152 #define	ERR_STR(msg_idx) \
153 	    (ib_get_msg((msg_idx), ib_error_msgs, MSG_TBL_SZ(ib_error_msgs)))
154 
155 /* Defines for "usage" */
156 #define	CFGA_IB_HELP_HEADER	1	/* Header only */
157 #define	CFGA_IB_HELP_CONFIG	2	/* -c usage help */
158 #define	CFGA_IB_HELP_LIST	3	/* -x list_clients usage help */
159 #define	CFGA_IB_HELP_UPD_PKEY	4	/* -x update_pkey_tbls usage help */
160 #define	CFGA_IB_HELP_CONF_FILE1	5	/* -x [add_service|delete_service] */
161 #define	CFGA_IB_HELP_CONF_FILE2	6	/* -x list_services help */
162 #define	CFGA_IB_HELP_UPD_IOC_CONF	\
163 				7	/* -x update_ioc_config help */
164 #define	CFGA_IB_HELP_UNCFG_CLNTS \
165 				8	/* -x unconfig_clients usage help */
166 #define	CFGA_IB_HELP_UNKNOWN	9	/* unknown help */
167 
168 #define	IB_RETRY_DEVPATH	12	/* devicepath show up: retry count */
169 #define	IB_MAX_DEVPATH_DELAY	6	/* sleep for 6 seconds */
170 #define	IB_NUM_NVPAIRS		6	/* for "info", "ap_id" etc. */
171 
172 /* Misc text strings */
173 #define	CFGA_DEV_DIR			"/dev/cfg"
174 #define	IB_STATIC_APID			"/dev/cfg/ib"
175 #define	MINOR_SEP			":"
176 #define	IB_APID				"apid"
177 #define	IB_CFGADM_DEFAULT_AP_TYPE	"unknown"
178 #define	IB_PORT_TYPE			"IB-PORT"
179 #define	IB_FABRIC_INFO			"InfiniBand Fabric"
180 #define	IB_HCA_TYPE			"IB-HCA"
181 #define	IB_IOC_TYPE			"IB-IOC"
182 #define	IB_VPPA_TYPE			"IB-VPPA"
183 #define	IB_HCASVC_TYPE			"IB-HCA_SVC"
184 #define	IB_PSEUDO_TYPE			"IB-PSEUDO"
185 #define	IB_FABRIC_TYPE			"IB-Fabric"
186 #define	IB_FABRIC_APID_STR		"ib:fabric"
187 
188 /* -x commands */
189 #define	IB_LIST_HCA_CLIENTS		"list_clients"		/* list HCA's */
190 								/* clients */
191 #define	IB_UNCONFIG_HCA_CLIENTS		"unconfig_clients"	/* unconfig */
192 								/* HCA's */
193 								/* clients */
194 #define	IB_UPDATE_PKEY_TBLS		"update_pkey_tbls"	/* re-read */
195 								/* P_Keys */
196 #define	IB_ADD_SERVICE			"add_service"		/* add svc */
197 #define	IB_DELETE_SERVICE		"delete_service"	/* delete svc */
198 #define	IB_LIST_SERVICES		"list_services"		/* list svcs */
199 #define	IB_UPDATE_IOC_CONF		"update_ioc_config"	/* update IOC */
200 								/* config */
201 
202 /* for confirm operation */
203 #define	IB_CONFIRM0	"the device: "
204 #define	IB_CONFIRM1 \
205 	"This operation will suspend activity on the IB device\nContinue"
206 #define	IB_CONFIRM2	"Unconfigure Clients of HCA"
207 #define	IB_CONFIRM3 \
208 	"This operation will unconfigure IB clients of this HCA\nContinue"
209 #define	IB_CONFIRM4 \
210 	"This operation will update P_Key tables for all ports of all HCAs"
211 #define	IB_CONFIRM5 \
212 	"This operation can update properties of IOC devices."
213 
214 /*
215  * Export "node_type"s from ibnex_node_type_t (see ibnex.h) to
216  * cfgadm in user land. NOTE: If ibnex_node_type_t changes in
217  * ibnex.h; do not forget to update these values here as well.
218  */
219 #define	IBNEX_PORT_NODE_TYPE		0
220 #define	IBNEX_VPPA_NODE_TYPE		1
221 #define	IBNEX_HCASVC_NODE_TYPE		2
222 #define	IBNEX_IOC_NODE_TYPE		3
223 #define	IBNEX_PSEUDO_NODE_TYPE		4
224 
225 /* for ib.conf file support */
226 #define	IBCONF_ADD_ENTRY		1
227 #define	IBCONF_DELETE_ENTRY		2
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* _CFGA_IB_H */
234