xref: /onnv-gate/usr/src/lib/cfgadm_plugins/ib/common/cfga_ib.h (revision 8082:f52c9d98dc8c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8082SRamaswamy.Tummala@Sun.COM  * Common Development and Distribution License (the "License").
6*8082SRamaswamy.Tummala@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*8082SRamaswamy.Tummala@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _CFGA_IB_H
270Sstevel@tonic-gate #define	_CFGA_IB_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef __cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <stdlib.h>
340Sstevel@tonic-gate #include <strings.h>
350Sstevel@tonic-gate #include <fcntl.h>
360Sstevel@tonic-gate #include <ctype.h>
370Sstevel@tonic-gate #include <unistd.h>
380Sstevel@tonic-gate #include <libintl.h>
390Sstevel@tonic-gate #include <sys/types32.h>
400Sstevel@tonic-gate #include <sys/varargs.h>
410Sstevel@tonic-gate #include <sys/ib/ibnex/ibnex_devctl.h>
420Sstevel@tonic-gate #include <libdevinfo.h>
430Sstevel@tonic-gate #include <libdevice.h>
440Sstevel@tonic-gate #include <librcm.h>
450Sstevel@tonic-gate #include <synch.h>
460Sstevel@tonic-gate #include <thread.h>
470Sstevel@tonic-gate #include <assert.h>
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #define	CFGA_PLUGIN_LIB
500Sstevel@tonic-gate #include <config_admin.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * Debug stuff.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate #ifdef	DEBUG
570Sstevel@tonic-gate #define	DPRINTF	printf
580Sstevel@tonic-gate #else
590Sstevel@tonic-gate #define	DPRINTF 0 &&
600Sstevel@tonic-gate #endif /* DEBUG */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /* for walking links */
640Sstevel@tonic-gate typedef struct walk_link {
650Sstevel@tonic-gate 	char *path;
660Sstevel@tonic-gate 	char len;
670Sstevel@tonic-gate 	char **linkpp;
680Sstevel@tonic-gate } walk_link_t;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Stuff carried over for the routines borrowed from cfgadm/SCSI.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate #define	MATCH_MINOR_NAME	1
750Sstevel@tonic-gate #define	S_FREE(x)	(((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /* Return/error codes */
780Sstevel@tonic-gate typedef enum {
790Sstevel@tonic-gate 	ICFGA_ERR = -2,
800Sstevel@tonic-gate 	ICFGA_LIB_ERR,
810Sstevel@tonic-gate 	ICFGA_OK,
820Sstevel@tonic-gate 	ICFGA_BUSY,
830Sstevel@tonic-gate 	ICFGA_NO_REC
840Sstevel@tonic-gate } icfga_ret_t;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /* Error Messages */
880Sstevel@tonic-gate typedef struct {
890Sstevel@tonic-gate 	int		intl;		/* Flag: if 1, internationalize */
900Sstevel@tonic-gate 	cfga_err_t	cfga_err;	/* Error code for libcfgadm */
910Sstevel@tonic-gate 	const char	*msgstr;
920Sstevel@tonic-gate } msgcvt_t;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /* "intl" defines */
950Sstevel@tonic-gate #define	NO_CVT			0
960Sstevel@tonic-gate #define	CVT			1
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #define	MSG_TBL_SZ(table)	(sizeof ((table)) / sizeof (msgcvt_t))
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /* Error message ids (and indices into ib_error_msgs) "cfga_err values " */
1020Sstevel@tonic-gate typedef enum {
1030Sstevel@tonic-gate 	CFGA_IB_OK = 0,			/* Plugin Related Errors */
1040Sstevel@tonic-gate 	CFGA_IB_UNKNOWN,
1050Sstevel@tonic-gate 	CFGA_IB_INTERNAL_ERR,
1060Sstevel@tonic-gate 	CFGA_IB_INVAL_ARG_ERR,
1070Sstevel@tonic-gate 	CFGA_IB_OPTIONS_ERR,
1080Sstevel@tonic-gate 	CFGA_IB_AP_ERR,
1090Sstevel@tonic-gate 	CFGA_IB_DEVCTL_ERR,
1100Sstevel@tonic-gate 	CFGA_IB_NOT_CONNECTED,
1110Sstevel@tonic-gate 	CFGA_IB_NOT_CONFIGURED,
1120Sstevel@tonic-gate 	CFGA_IB_ALREADY_CONNECTED,
1130Sstevel@tonic-gate 	CFGA_IB_ALREADY_CONFIGURED,
1140Sstevel@tonic-gate 	CFGA_IB_CONFIG_OP_ERR,
1150Sstevel@tonic-gate 	CFGA_IB_UNCONFIG_OP_ERR,
1160Sstevel@tonic-gate 	CFGA_IB_OPEN_ERR,
1170Sstevel@tonic-gate 	CFGA_IB_IOCTL_ERR,
1180Sstevel@tonic-gate 	CFGA_IB_BUSY_ERR,
1190Sstevel@tonic-gate 	CFGA_IB_ALLOC_FAIL,
1200Sstevel@tonic-gate 	CFGA_IB_OPNOTSUPP,
1210Sstevel@tonic-gate 	CFGA_IB_INVAL_APID_ERR,
1220Sstevel@tonic-gate 	CFGA_IB_DEVLINK_ERR,
1230Sstevel@tonic-gate 	CFGA_IB_PRIV_ERR,
1240Sstevel@tonic-gate 	CFGA_IB_NVLIST_ERR,
1250Sstevel@tonic-gate 	CFGA_IB_HCA_LIST_ERR,
1260Sstevel@tonic-gate 	CFGA_IB_HCA_UNCONFIG_ERR,
1270Sstevel@tonic-gate 	CFGA_IB_UPD_PKEY_TBLS_ERR,
1280Sstevel@tonic-gate 	CFGA_IB_CONFIG_FILE_ERR,
1290Sstevel@tonic-gate 	CFGA_IB_LOCK_FILE_ERR,
1300Sstevel@tonic-gate 	CFGA_IB_UNLOCK_FILE_ERR,
1310Sstevel@tonic-gate 	CFGA_IB_COMM_INVAL_ERR,
1320Sstevel@tonic-gate 	CFGA_IB_SVC_INVAL_ERR,
1330Sstevel@tonic-gate 	CFGA_IB_SVC_LEN_ERR,
1340Sstevel@tonic-gate 	CFGA_IB_SVC_EXISTS_ERR,
1350Sstevel@tonic-gate 	CFGA_IB_SVC_NO_EXIST_ERR,
1360Sstevel@tonic-gate 	CFGA_IB_UCFG_CLNTS_ERR,
1370Sstevel@tonic-gate 	CFGA_IB_INVALID_OP_ERR,
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	CFGA_IB_RCM_HANDLE_ERR,		/* Plugin's RCM Related Errors */
1400Sstevel@tonic-gate 	CFGA_IB_RCM_ONLINE_ERR,
1410Sstevel@tonic-gate 	CFGA_IB_RCM_OFFLINE_ERR
1420Sstevel@tonic-gate } cfga_ib_ret_t;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate  * Given an error msg index, look up the associated string, and
1470Sstevel@tonic-gate  * convert it to the current locale if required.
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate #define	ERR_STR(msg_idx) \
1500Sstevel@tonic-gate 	    (ib_get_msg((msg_idx), ib_error_msgs, MSG_TBL_SZ(ib_error_msgs)))
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /* Defines for "usage" */
1530Sstevel@tonic-gate #define	CFGA_IB_HELP_HEADER	1	/* Header only */
1540Sstevel@tonic-gate #define	CFGA_IB_HELP_CONFIG	2	/* -c usage help */
1550Sstevel@tonic-gate #define	CFGA_IB_HELP_LIST	3	/* -x list_clients usage help */
1560Sstevel@tonic-gate #define	CFGA_IB_HELP_UPD_PKEY	4	/* -x update_pkey_tbls usage help */
1570Sstevel@tonic-gate #define	CFGA_IB_HELP_CONF_FILE1	5	/* -x [add_service|delete_service] */
1580Sstevel@tonic-gate #define	CFGA_IB_HELP_CONF_FILE2	6	/* -x list_services help */
1590Sstevel@tonic-gate #define	CFGA_IB_HELP_UPD_IOC_CONF	\
1600Sstevel@tonic-gate 				7	/* -x update_ioc_config help */
1610Sstevel@tonic-gate #define	CFGA_IB_HELP_UNCFG_CLNTS \
1620Sstevel@tonic-gate 				8	/* -x unconfig_clients usage help */
1630Sstevel@tonic-gate #define	CFGA_IB_HELP_UNKNOWN	9	/* unknown help */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #define	IB_RETRY_DEVPATH	12	/* devicepath show up: retry count */
1660Sstevel@tonic-gate #define	IB_MAX_DEVPATH_DELAY	6	/* sleep for 6 seconds */
1670Sstevel@tonic-gate #define	IB_NUM_NVPAIRS		6	/* for "info", "ap_id" etc. */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /* Misc text strings */
1700Sstevel@tonic-gate #define	CFGA_DEV_DIR			"/dev/cfg"
1710Sstevel@tonic-gate #define	IB_STATIC_APID			"/dev/cfg/ib"
1720Sstevel@tonic-gate #define	MINOR_SEP			":"
1730Sstevel@tonic-gate #define	IB_APID				"apid"
1740Sstevel@tonic-gate #define	IB_CFGADM_DEFAULT_AP_TYPE	"unknown"
1750Sstevel@tonic-gate #define	IB_PORT_TYPE			"IB-PORT"
1760Sstevel@tonic-gate #define	IB_FABRIC_INFO			"InfiniBand Fabric"
1770Sstevel@tonic-gate #define	IB_HCA_TYPE			"IB-HCA"
1780Sstevel@tonic-gate #define	IB_IOC_TYPE			"IB-IOC"
1790Sstevel@tonic-gate #define	IB_VPPA_TYPE			"IB-VPPA"
1800Sstevel@tonic-gate #define	IB_HCASVC_TYPE			"IB-HCA_SVC"
1810Sstevel@tonic-gate #define	IB_PSEUDO_TYPE			"IB-PSEUDO"
1820Sstevel@tonic-gate #define	IB_FABRIC_TYPE			"IB-Fabric"
1830Sstevel@tonic-gate #define	IB_FABRIC_APID_STR		"ib:fabric"
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /* -x commands */
1860Sstevel@tonic-gate #define	IB_LIST_HCA_CLIENTS		"list_clients"		/* list HCA's */
1870Sstevel@tonic-gate 								/* clients */
1880Sstevel@tonic-gate #define	IB_UNCONFIG_HCA_CLIENTS		"unconfig_clients"	/* unconfig */
1890Sstevel@tonic-gate 								/* HCA's */
1900Sstevel@tonic-gate 								/* clients */
1910Sstevel@tonic-gate #define	IB_UPDATE_PKEY_TBLS		"update_pkey_tbls"	/* re-read */
1920Sstevel@tonic-gate 								/* P_Keys */
1930Sstevel@tonic-gate #define	IB_ADD_SERVICE			"add_service"		/* add svc */
1940Sstevel@tonic-gate #define	IB_DELETE_SERVICE		"delete_service"	/* delete svc */
1950Sstevel@tonic-gate #define	IB_LIST_SERVICES		"list_services"		/* list svcs */
1960Sstevel@tonic-gate #define	IB_UPDATE_IOC_CONF		"update_ioc_config"	/* update IOC */
1970Sstevel@tonic-gate 								/* config */
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /* for confirm operation */
2000Sstevel@tonic-gate #define	IB_CONFIRM1 \
2010Sstevel@tonic-gate 	"This operation will suspend activity on the IB device\nContinue"
2020Sstevel@tonic-gate #define	IB_CONFIRM3 \
2030Sstevel@tonic-gate 	"This operation will unconfigure IB clients of this HCA\nContinue"
2040Sstevel@tonic-gate #define	IB_CONFIRM4 \
2050Sstevel@tonic-gate 	"This operation will update P_Key tables for all ports of all HCAs"
2060Sstevel@tonic-gate #define	IB_CONFIRM5 \
2070Sstevel@tonic-gate 	"This operation can update properties of IOC devices."
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * Export "node_type"s from ibnex_node_type_t (see ibnex.h) to
2110Sstevel@tonic-gate  * cfgadm in user land. NOTE: If ibnex_node_type_t changes in
2120Sstevel@tonic-gate  * ibnex.h; do not forget to update these values here as well.
2130Sstevel@tonic-gate  */
2140Sstevel@tonic-gate #define	IBNEX_PORT_NODE_TYPE		0
2150Sstevel@tonic-gate #define	IBNEX_VPPA_NODE_TYPE		1
2160Sstevel@tonic-gate #define	IBNEX_HCASVC_NODE_TYPE		2
2170Sstevel@tonic-gate #define	IBNEX_IOC_NODE_TYPE		3
2180Sstevel@tonic-gate #define	IBNEX_PSEUDO_NODE_TYPE		4
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate /* for ib.conf file support */
2210Sstevel@tonic-gate #define	IBCONF_ADD_ENTRY		1
2220Sstevel@tonic-gate #define	IBCONF_DELETE_ENTRY		2
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate #ifdef __cplusplus
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate #endif
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate #endif /* _CFGA_IB_H */
229