xref: /onnv-gate/usr/src/lib/cfgadm_plugins/pci/common/cfga.c (revision 58:f37950de9bc8)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
22*58Sanish 
230Sstevel@tonic-gate /*
24*58Sanish  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  *	Plugin Library for PCI Hot-Plug Controller
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <stddef.h>
350Sstevel@tonic-gate #include <locale.h>
360Sstevel@tonic-gate #include <ctype.h>
370Sstevel@tonic-gate #include <stdio.h>
380Sstevel@tonic-gate #include <stdlib.h>
390Sstevel@tonic-gate #include <string.h>
400Sstevel@tonic-gate #include <fcntl.h>
410Sstevel@tonic-gate #include <unistd.h>
420Sstevel@tonic-gate #include <errno.h>
430Sstevel@tonic-gate #include <locale.h>
440Sstevel@tonic-gate #include <langinfo.h>
450Sstevel@tonic-gate #include <time.h>
460Sstevel@tonic-gate #include <sys/param.h>
470Sstevel@tonic-gate #include <stdarg.h>
480Sstevel@tonic-gate #include <libdevinfo.h>
490Sstevel@tonic-gate #include <libdevice.h>
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #define	CFGA_PLUGIN_LIB
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #include <config_admin.h>
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #include <sys/types.h>
560Sstevel@tonic-gate #include <sys/stat.h>
570Sstevel@tonic-gate #include <sys/ioctl.h>
580Sstevel@tonic-gate #include <sys/dditypes.h>
590Sstevel@tonic-gate #include <sys/devctl.h>
600Sstevel@tonic-gate #include <sys/modctl.h>
610Sstevel@tonic-gate #include <sys/hotplug/hpctrl.h>
620Sstevel@tonic-gate #include <sys/pci.h>
630Sstevel@tonic-gate #include <libintl.h>
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #include <dirent.h>
660Sstevel@tonic-gate #include <limits.h>
670Sstevel@tonic-gate #include <sys/mkdev.h>
680Sstevel@tonic-gate #include <librcm.h>
69*58Sanish #include "../../../../common/pci/pci_strings.h"
70*58Sanish 
71*58Sanish extern const struct pci_class_strings_s class_pci[];
72*58Sanish extern int class_pci_items;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * Set the version number
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate int cfga_version = CFGA_HSL_V2;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #ifdef	DEBUG
800Sstevel@tonic-gate #define	PCIHP_DBG	1
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
840Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
850Sstevel@tonic-gate #endif
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate  *	DEBUGING LEVEL
890Sstevel@tonic-gate  *
900Sstevel@tonic-gate  * 	External routines:  1 - 2
910Sstevel@tonic-gate  *	Internal routines:  3 - 4
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate #ifdef	PCIHP_DBG
940Sstevel@tonic-gate int	pcihp_debug = 1;
950Sstevel@tonic-gate #define	DBG(level, args) \
960Sstevel@tonic-gate 	{ if (pcihp_debug >= (level)) printf args; }
970Sstevel@tonic-gate #define	DBG_F(level, args) \
980Sstevel@tonic-gate 	{ if (pcihp_debug >= (level)) fprintf args; }
990Sstevel@tonic-gate #else
1000Sstevel@tonic-gate #define	DBG(level, args)	/* nothing */
1010Sstevel@tonic-gate #define	DBG_F(level, args)	/* nothing */
1020Sstevel@tonic-gate #endif
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #define	CMD_ACQUIRE		0
1050Sstevel@tonic-gate #define	CMD_GETSTAT		1
1060Sstevel@tonic-gate #define	CMD_LIST		2
1070Sstevel@tonic-gate #define	CMD_SLOT_CONNECT	3
1080Sstevel@tonic-gate #define	CMD_SLOT_DISCONNECT	4
1090Sstevel@tonic-gate #define	CMD_SLOT_CONFIGURE	5
1100Sstevel@tonic-gate #define	CMD_SLOT_UNCONFIGURE	6
1110Sstevel@tonic-gate #define	CMD_SLOT_INSERT		7
1120Sstevel@tonic-gate #define	CMD_SLOT_REMOVE		8
1130Sstevel@tonic-gate #define	CMD_OPEN		9
1140Sstevel@tonic-gate #define	CMD_FSTAT		10
1150Sstevel@tonic-gate #define	ERR_CMD_INVAL		11
1160Sstevel@tonic-gate #define	ERR_AP_INVAL		12
1170Sstevel@tonic-gate #define	ERR_AP_ERR		13
1180Sstevel@tonic-gate #define	ERR_OPT_INVAL		14
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate static char *
1210Sstevel@tonic-gate cfga_errstrs[] = {
1220Sstevel@tonic-gate 	/* n */ "acquire ",
1230Sstevel@tonic-gate 	/* n */ "get-status ",
1240Sstevel@tonic-gate 	/* n */ "list ",
1250Sstevel@tonic-gate 	/* n */ "connect ",
1260Sstevel@tonic-gate 	/* n */ "disconnect ",
1270Sstevel@tonic-gate 	/* n */ "configure ",
1280Sstevel@tonic-gate 	/* n */ "unconfigure ",
1290Sstevel@tonic-gate 	/* n */ "insert ",
1300Sstevel@tonic-gate 	/* n */ "remove ",
1310Sstevel@tonic-gate 	/* n */ "open ",
1320Sstevel@tonic-gate 	/* n */ "fstat ",
1330Sstevel@tonic-gate 	/* y */ "invalid command ",
1340Sstevel@tonic-gate 	/* y */ "invalid attachment point ",
1350Sstevel@tonic-gate 	/* y */ "invalid transition ",
1360Sstevel@tonic-gate 	/* y */ "invalid option ",
1370Sstevel@tonic-gate 		NULL
1380Sstevel@tonic-gate };
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #define	HELP_HEADER		1
1410Sstevel@tonic-gate #define	HELP_CONFIG		2
1420Sstevel@tonic-gate #define	HELP_ENABLE_SLOT	3
1430Sstevel@tonic-gate #define	HELP_DISABLE_SLOT	4
1440Sstevel@tonic-gate #define	HELP_ENABLE_AUTOCONF	5
1450Sstevel@tonic-gate #define	HELP_DISABLE_AUTOCONF	6
1460Sstevel@tonic-gate #define	HELP_LED_CNTRL		7
1470Sstevel@tonic-gate #define	HELP_UNKNOWN		8
1480Sstevel@tonic-gate #define	SUCCESS			9
1490Sstevel@tonic-gate #define	FAILED			10
1500Sstevel@tonic-gate #define	UNKNOWN			11
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	MAXLINE			256
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /* for type string assembly in get_type() */
1550Sstevel@tonic-gate #define	TPCT(s)	(void) strlcat(buf, (s), CFGA_TYPE_LEN)
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate extern int errno;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate static void cfga_err(char **errstring, ...);
1600Sstevel@tonic-gate static cfga_err_t fix_ap_name(char *ap_log_id, const char *ap_id,
1610Sstevel@tonic-gate     char *slot_name, char **errstring);
1620Sstevel@tonic-gate static void build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
1630Sstevel@tonic-gate     void *retdata);
1640Sstevel@tonic-gate static cfga_err_t check_options(const char *options);
1650Sstevel@tonic-gate static void cfga_msg(struct cfga_msg *msgp, const char *str);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate static char *
1680Sstevel@tonic-gate cfga_strs[] = {
1690Sstevel@tonic-gate NULL,
1700Sstevel@tonic-gate "\nPCI hotplug specific commands:",
1710Sstevel@tonic-gate "\t-c [connect|disconnect|configure|unconfigure|insert|remove] "
1720Sstevel@tonic-gate "ap_id [ap_id...]",
1730Sstevel@tonic-gate "\t-x enable_slot  ap_id [ap_id...]",
1740Sstevel@tonic-gate "\t-x disable_slot ap_id [ap_id...]",
1750Sstevel@tonic-gate "\t-x enable_autoconfig  ap_id [ap_id...]",
1760Sstevel@tonic-gate "\t-x disable_autoconfig ap_id [ap_id...]",
1770Sstevel@tonic-gate "\t-x led[=[fault|power|active|attn],mode=[on|off|blink]] ap_id [ap_id...]",
1780Sstevel@tonic-gate "\tunknown command or option: ",
1790Sstevel@tonic-gate "success   ",
1800Sstevel@tonic-gate "failed   ",
1810Sstevel@tonic-gate "unknown",
1820Sstevel@tonic-gate NULL
1830Sstevel@tonic-gate };
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate #define	MAX_FORMAT 80
1860Sstevel@tonic-gate 
187*58Sanish #define	ENABLE_SLOT	0
188*58Sanish #define	DISABLE_SLOT	1
189*58Sanish #define	ENABLE_AUTOCNF	2
190*58Sanish #define	DISABLE_AUTOCNF	3
191*58Sanish #define	LED		4
192*58Sanish #define	MODE		5
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate  * Board Type
1960Sstevel@tonic-gate  */
1970Sstevel@tonic-gate static char *
1980Sstevel@tonic-gate board_strs[] = {
1990Sstevel@tonic-gate 	/* n */ "???",	/* HPC_BOARD_UNKNOWN */
2000Sstevel@tonic-gate 	/* n */ "hp",	/* HPC_BOARD_PCI_HOTPLUG */
2010Sstevel@tonic-gate 	/* n */ "nhs",	/* HPC_BOARD_CPCI_NON_HS */
2020Sstevel@tonic-gate 	/* n */ "bhs",  /* HPC_BOARD_CPCI_BASIC_HS */
2030Sstevel@tonic-gate 	/* n */ "fhs",	/* HPC_BOARD_CPCI_FULL_HS */
2040Sstevel@tonic-gate 	/* n */ "hs",	/* HPC_BOARD_CPCI_HS */
2050Sstevel@tonic-gate 	/* n */ NULL
2060Sstevel@tonic-gate };
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /*
2090Sstevel@tonic-gate  * HW functions
2100Sstevel@tonic-gate  */
2110Sstevel@tonic-gate static char *
2120Sstevel@tonic-gate func_strs[] = {
213*58Sanish 	/* n */ "enable_slot",
2140Sstevel@tonic-gate 	/* n */ "disable_slot",
2150Sstevel@tonic-gate 	/* n */ "enable_autoconfig",
2160Sstevel@tonic-gate 	/* n */ "disable_autoconfig",
2170Sstevel@tonic-gate 	/* n */ "led",
2180Sstevel@tonic-gate 	/* n */ "mode",
2190Sstevel@tonic-gate 	/* n */ NULL
2200Sstevel@tonic-gate };
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate /*
2230Sstevel@tonic-gate  * LED strings
2240Sstevel@tonic-gate  */
2250Sstevel@tonic-gate static char *
2260Sstevel@tonic-gate led_strs[] = {
2270Sstevel@tonic-gate 	/* n */ "fault",	/* HPC_FAULT_LED */
2280Sstevel@tonic-gate 	/* n */ "power",	/* HPC_POWER_LED */
2290Sstevel@tonic-gate 	/* n */ "attn",		/* HPC_ATTN_LED */
2300Sstevel@tonic-gate 	/* n */ "active",	/* HPC_ACTIVE_LED */
2310Sstevel@tonic-gate 	/* n */ NULL
2320Sstevel@tonic-gate };
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate #define	FAULT	0
2350Sstevel@tonic-gate #define	POWER	1
2360Sstevel@tonic-gate #define	ATTN	2
2370Sstevel@tonic-gate #define	ACTIVE	3
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate static char *
2400Sstevel@tonic-gate mode_strs[] = {
2410Sstevel@tonic-gate 	/* n */ "off",		/* HPC_LED_OFF */
2420Sstevel@tonic-gate 	/* n */ "on",		/* HPC_LED_ON */
2430Sstevel@tonic-gate 	/* n */ "blink",	/* HPC_LED_BLINK */
2440Sstevel@tonic-gate 	/* n */	NULL
2450Sstevel@tonic-gate };
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate #define	OFF	0
2480Sstevel@tonic-gate #define	ON	1
2490Sstevel@tonic-gate #define	BLINK	2
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate #define	cfga_errstrs(i)		cfga_errstrs[(i)]
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate #define	cfga_eid(a, b)		(((a) << 8) + (b))
2540Sstevel@tonic-gate #define	MAXDEVS			32
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate typedef enum {
2570Sstevel@tonic-gate 	SOLARIS_SLT_NAME,
2580Sstevel@tonic-gate 	PROM_SLT_NAME
2590Sstevel@tonic-gate } slt_name_src_t;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate struct searcharg {
2620Sstevel@tonic-gate 	char	*devpath;
2630Sstevel@tonic-gate 	char	slotnames[MAXDEVS][MAXNAMELEN];
2640Sstevel@tonic-gate 	int	minor;
2650Sstevel@tonic-gate 	di_prom_handle_t	promp;
2660Sstevel@tonic-gate 	slt_name_src_t	slt_name_src;
2670Sstevel@tonic-gate };
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate static void *private_check;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate static int
2720Sstevel@tonic-gate get_occupants(const char *ap_id, hpc_occupant_info_t *occupant)
2730Sstevel@tonic-gate {
2740Sstevel@tonic-gate 	int rv;
2750Sstevel@tonic-gate 	int fd;
2760Sstevel@tonic-gate 	di_node_t ap_node;
2770Sstevel@tonic-gate 	char *prop_data;
2780Sstevel@tonic-gate 	char *tmp;
2790Sstevel@tonic-gate 	char *ptr;
2800Sstevel@tonic-gate 	struct stat statbuf;
2810Sstevel@tonic-gate 	dev_t devt;
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
2840Sstevel@tonic-gate 		DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
2850Sstevel@tonic-gate 		DBG_F(2, (stderr, "open on %s failed\n", ap_id));
2860Sstevel@tonic-gate 		return (CFGA_ERROR);
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	if (fstat(fd, &statbuf) == -1) {
2900Sstevel@tonic-gate 		DBG(1, ("stat failed: %i\n", errno));
2910Sstevel@tonic-gate 		(void) close(fd);
2920Sstevel@tonic-gate 		return (CFGA_ERROR);
2930Sstevel@tonic-gate 	}
2940Sstevel@tonic-gate 	(void) close(fd);
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	devt = statbuf.st_rdev;
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	tmp = (char *)(ap_id + sizeof ("/devices") - 1);
2990Sstevel@tonic-gate 	if ((ptr = strrchr(tmp, ':')) != NULL)
3000Sstevel@tonic-gate 		*ptr = '\0';
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	ap_node = di_init(tmp, DINFOPROP | DINFOMINOR);
3030Sstevel@tonic-gate 	if (ap_node == DI_NODE_NIL) {
3040Sstevel@tonic-gate 		DBG(1, ("dead %i\n", errno));
3050Sstevel@tonic-gate 		return (CFGA_ERROR);
3060Sstevel@tonic-gate 	}
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate #ifdef	PCIHP_DBG
3090Sstevel@tonic-gate 	ptr = di_devfs_path(ap_node);
3100Sstevel@tonic-gate 	DBG(1, ("get_occupants: %s\n", ptr));
3110Sstevel@tonic-gate 	di_devfs_path_free(ptr);
3120Sstevel@tonic-gate #endif
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	if ((rv = di_prop_lookup_strings(devt, ap_node, "pci-occupant",
3150Sstevel@tonic-gate 	    &prop_data)) == -1) {
3160Sstevel@tonic-gate 		DBG(1, ("get_occupants: prop_lookup failed: %i\n", errno));
3170Sstevel@tonic-gate 		di_fini(ap_node);
3180Sstevel@tonic-gate 		return (CFGA_ERROR);
3190Sstevel@tonic-gate 	}
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 	if (prop_data && (strcmp(prop_data, "") == 0)) {
3220Sstevel@tonic-gate 		di_fini(ap_node);
3230Sstevel@tonic-gate 		occupant->i = 0;
3240Sstevel@tonic-gate 		occupant->id[0] = NULL;
3250Sstevel@tonic-gate 		return (CFGA_OK);
3260Sstevel@tonic-gate 	}
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	DBG(1, ("get_occupants: %i devices found\n", rv));
3290Sstevel@tonic-gate 	for (occupant->i = 0; occupant->i < rv; occupant->i++) {
3300Sstevel@tonic-gate 		if (occupant->i >= (HPC_MAX_OCCUPANTS - 1)) {
3310Sstevel@tonic-gate 			occupant->i--;
3320Sstevel@tonic-gate 			break;
3330Sstevel@tonic-gate 		}
3340Sstevel@tonic-gate 		occupant->id[occupant->i] = (char *)malloc(
3350Sstevel@tonic-gate 			strlen(prop_data) + sizeof ("/devices"));
3360Sstevel@tonic-gate 		(void) snprintf(occupant->id[occupant->i], strlen(prop_data) +
3370Sstevel@tonic-gate 		    sizeof ("/devices"), "/devices%s", prop_data);
3380Sstevel@tonic-gate 		DBG(1, ("%s\n", occupant->id[occupant->i]));
3390Sstevel@tonic-gate 		prop_data += strlen(prop_data) + 1;
3400Sstevel@tonic-gate 	}
3410Sstevel@tonic-gate 	di_fini(ap_node);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	occupant->id[occupant->i] = NULL;
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	return (CFGA_OK);
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate /*
3490Sstevel@tonic-gate  * let rcm know that the device has indeed been removed and clean
3500Sstevel@tonic-gate  * up rcm data
3510Sstevel@tonic-gate  */
3520Sstevel@tonic-gate static void
3530Sstevel@tonic-gate confirm_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
3540Sstevel@tonic-gate {
3550Sstevel@tonic-gate 	DBG(1, ("confirm_rcm\n"));
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	if (occupant->i == 0) /* nothing was found to ask rcm about */
3580Sstevel@tonic-gate 		return;
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	(void) rcm_notify_remove_list(rhandle, occupant->id, 0, NULL);
3610Sstevel@tonic-gate 	(void) rcm_free_handle(rhandle);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	for (; occupant->i >= 0; occupant->i--)
3640Sstevel@tonic-gate 		free(occupant->id[occupant->i]);
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate static void
3680Sstevel@tonic-gate fail_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate 	DBG(1, ("fail_rcm\n"));
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	if (occupant->i == 0) /* nothing was found to ask rcm about */
3730Sstevel@tonic-gate 		return;
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 	(void) rcm_notify_online_list(rhandle, occupant->id, 0, NULL);
3760Sstevel@tonic-gate 	(void) rcm_free_handle(rhandle);
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	for (; occupant->i >= 0; occupant->i--)
3790Sstevel@tonic-gate 		free(occupant->id[occupant->i]);
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate /*
3830Sstevel@tonic-gate  * copied from scsi_rcm_info_table
3840Sstevel@tonic-gate  *
3850Sstevel@tonic-gate  *      Takes an opaque rcm_info_t pointer and a character pointer, and appends
3860Sstevel@tonic-gate  * the rcm_info_t data in the form of a table to the given character pointer.
3870Sstevel@tonic-gate  */
3880Sstevel@tonic-gate static void
3890Sstevel@tonic-gate pci_rcm_info_table(rcm_info_t *rinfo, char **table)
3900Sstevel@tonic-gate {
3910Sstevel@tonic-gate 	int i;
3920Sstevel@tonic-gate 	size_t w;
3930Sstevel@tonic-gate 	size_t width = 0;
3940Sstevel@tonic-gate 	size_t w_rsrc = 0;
3950Sstevel@tonic-gate 	size_t w_info = 0;
3960Sstevel@tonic-gate 	size_t table_size = 0;
3970Sstevel@tonic-gate 	uint_t tuples = 0;
3980Sstevel@tonic-gate 	rcm_info_tuple_t *tuple = NULL;
3990Sstevel@tonic-gate 	char *rsrc;
4000Sstevel@tonic-gate 	char *info;
4010Sstevel@tonic-gate 	char *newtable;
4020Sstevel@tonic-gate 	static char format[MAX_FORMAT];
4030Sstevel@tonic-gate 	const char *infostr;
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	/* Protect against invalid arguments */
4060Sstevel@tonic-gate 	if (rinfo == NULL || table == NULL)
4070Sstevel@tonic-gate 		return;
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate 	/* Set localized table header strings */
4100Sstevel@tonic-gate 	rsrc = dgettext(TEXT_DOMAIN, "Resource");
4110Sstevel@tonic-gate 	info = dgettext(TEXT_DOMAIN, "Information");
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 	/* A first pass, to size up the RCM information */
4140Sstevel@tonic-gate 	while (tuple = rcm_info_next(rinfo, tuple)) {
4150Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
4160Sstevel@tonic-gate 			tuples++;
4170Sstevel@tonic-gate 			if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
4180Sstevel@tonic-gate 				w_rsrc = w;
4190Sstevel@tonic-gate 			if ((w = strlen(infostr)) > w_info)
4200Sstevel@tonic-gate 				w_info = w;
4210Sstevel@tonic-gate 		}
4220Sstevel@tonic-gate 	}
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate 	/* If nothing was sized up above, stop early */
4250Sstevel@tonic-gate 	if (tuples == 0)
4260Sstevel@tonic-gate 		return;
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	/* Adjust column widths for column headings */
4290Sstevel@tonic-gate 	if ((w = strlen(rsrc)) > w_rsrc)
4300Sstevel@tonic-gate 		w_rsrc = w;
4310Sstevel@tonic-gate 	else if ((w_rsrc - w) % 2)
4320Sstevel@tonic-gate 		w_rsrc++;
4330Sstevel@tonic-gate 	if ((w = strlen(info)) > w_info)
4340Sstevel@tonic-gate 		w_info = w;
4350Sstevel@tonic-gate 	else if ((w_info - w) % 2)
4360Sstevel@tonic-gate 		w_info++;
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 	/*
4390Sstevel@tonic-gate 	 * Compute the total line width of each line,
4400Sstevel@tonic-gate 	 * accounting for intercolumn spacing.
4410Sstevel@tonic-gate 	 */
4420Sstevel@tonic-gate 	width = w_info + w_rsrc + 4;
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate 	/* Allocate space for the table */
4450Sstevel@tonic-gate 	table_size = (2 + tuples) * (width + 1) + 2;
4460Sstevel@tonic-gate 	if (*table == NULL) {
4470Sstevel@tonic-gate 		/* zero fill for the strcat() call below */
4480Sstevel@tonic-gate 		*table = calloc(table_size, sizeof (char));
4490Sstevel@tonic-gate 		if (*table == NULL)
4500Sstevel@tonic-gate 			return;
4510Sstevel@tonic-gate 	} else {
4520Sstevel@tonic-gate 		newtable = realloc(*table, strlen(*table) + table_size);
4530Sstevel@tonic-gate 		if (newtable == NULL)
4540Sstevel@tonic-gate 			return;
4550Sstevel@tonic-gate 		else
4560Sstevel@tonic-gate 			*table = newtable;
4570Sstevel@tonic-gate 	}
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	/* Place a table header into the string */
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 	/* The resource header */
4620Sstevel@tonic-gate 	(void) strcat(*table, "\n");
4630Sstevel@tonic-gate 	w = strlen(rsrc);
4640Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
4650Sstevel@tonic-gate 		(void) strcat(*table, " ");
4660Sstevel@tonic-gate 	(void) strcat(*table, rsrc);
4670Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
4680Sstevel@tonic-gate 		(void) strcat(*table, " ");
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	/* The information header */
4710Sstevel@tonic-gate 	(void) strcat(*table, "  ");
4720Sstevel@tonic-gate 	w = strlen(info);
4730Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++)
4740Sstevel@tonic-gate 		(void) strcat(*table, " ");
4750Sstevel@tonic-gate 	(void) strcat(*table, info);
4760Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++)
4770Sstevel@tonic-gate 		(void) strcat(*table, " ");
4780Sstevel@tonic-gate 	/* Underline the headers */
4790Sstevel@tonic-gate 	(void) strcat(*table, "\n");
4800Sstevel@tonic-gate 	for (i = 0; i < w_rsrc; i++)
4810Sstevel@tonic-gate 		(void) strcat(*table, "-");
4820Sstevel@tonic-gate 	(void) strcat(*table, "  ");
4830Sstevel@tonic-gate 	for (i = 0; i < w_info; i++)
4840Sstevel@tonic-gate 		(void) strcat(*table, "-");
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 	/* Construct the format string */
4870Sstevel@tonic-gate 	(void) snprintf(format, MAX_FORMAT, "%%-%ds  %%-%ds",
4880Sstevel@tonic-gate 	    (int)w_rsrc, (int)w_info);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	/* Add the tuples to the table string */
4910Sstevel@tonic-gate 	tuple = NULL;
4920Sstevel@tonic-gate 	while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
4930Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
4940Sstevel@tonic-gate 			(void) strcat(*table, "\n");
4950Sstevel@tonic-gate 			(void) sprintf(&((*table)[strlen(*table)]),
4960Sstevel@tonic-gate 			    format, rcm_info_rsrc(tuple),
4970Sstevel@tonic-gate 			    infostr);
4980Sstevel@tonic-gate 		}
4990Sstevel@tonic-gate 	}
5000Sstevel@tonic-gate }
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate  * Figure out what device is about to be unconfigured or disconnected
5040Sstevel@tonic-gate  * and make sure rcm is ok with it.
5050Sstevel@tonic-gate  * hangs on to a list of handles so they can then be confirmed or denied
5060Sstevel@tonic-gate  * if either getting the occupant list or talking to rcm fails
5070Sstevel@tonic-gate  * return CFGA_ERROR so that things can go on without rcm
5080Sstevel@tonic-gate  */
5090Sstevel@tonic-gate static int
5100Sstevel@tonic-gate check_rcm(const char *ap_id, hpc_occupant_info_t *occupant,
5110Sstevel@tonic-gate     rcm_handle_t **rhandlep, char **errstring, cfga_flags_t flags)
5120Sstevel@tonic-gate {
5130Sstevel@tonic-gate 	int rv;
5140Sstevel@tonic-gate 	rcm_info_t *rinfo;
5150Sstevel@tonic-gate 	rcm_handle_t *rhandle;
5160Sstevel@tonic-gate 	uint_t rcmflags;
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 	if (get_occupants(ap_id, occupant) != 0) {
5190Sstevel@tonic-gate 		DBG(1, ("check_rcm: failed to get occupants\n"));
5200Sstevel@tonic-gate 		return (CFGA_ERROR);
5210Sstevel@tonic-gate 	}
5220Sstevel@tonic-gate 
5230Sstevel@tonic-gate 	if (occupant->i == 0) {
5240Sstevel@tonic-gate 		DBG(1, ("check_rcm: no drivers attaching to occupants\n"));
5250Sstevel@tonic-gate 		return (CFGA_OK);
5260Sstevel@tonic-gate 	}
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	if (rcm_alloc_handle(NULL, 0, NULL, &rhandle)
5290Sstevel@tonic-gate 	    != RCM_SUCCESS) {
5300Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by rcm failure\n"));
5310Sstevel@tonic-gate 		return (CFGA_ERROR);
5320Sstevel@tonic-gate 	}
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 	rcmflags = (flags & CFGA_FLAG_FORCE) ? RCM_FORCE : 0;
5350Sstevel@tonic-gate 	rv = rcm_request_offline_list(rhandle, occupant->id, rcmflags, &rinfo);
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	if (rv == RCM_FAILURE) {
5380Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by rcm failure 2\n"));
5390Sstevel@tonic-gate 		pci_rcm_info_table(rinfo, errstring);
5400Sstevel@tonic-gate 		rcm_free_info(rinfo);
5410Sstevel@tonic-gate 		fail_rcm(occupant, rhandle);
5420Sstevel@tonic-gate 		return (CFGA_BUSY);
5430Sstevel@tonic-gate 	}
5440Sstevel@tonic-gate 	if (rv == RCM_CONFLICT) {
5450Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by %i\n",
5460Sstevel@tonic-gate 		    rcm_info_pid(rinfo)));
5470Sstevel@tonic-gate 		pci_rcm_info_table(rinfo, errstring);
5480Sstevel@tonic-gate 		rcm_free_info(rinfo);
5490Sstevel@tonic-gate 		(void) rcm_free_handle(rhandle);
5500Sstevel@tonic-gate 		for (; occupant->i >= 0; occupant->i--)
5510Sstevel@tonic-gate 			free(occupant->id[occupant->i]);
5520Sstevel@tonic-gate 		return (CFGA_BUSY);
5530Sstevel@tonic-gate 	}
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 	rcm_free_info(rinfo);
5560Sstevel@tonic-gate 	*rhandlep = rhandle;
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate 	/* else */
5590Sstevel@tonic-gate 	return (CFGA_OK);
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 
5630Sstevel@tonic-gate /*
5640Sstevel@tonic-gate  * Transitional Diagram:
5650Sstevel@tonic-gate  *
5660Sstevel@tonic-gate  *  empty		unconfigure
5670Sstevel@tonic-gate  * (remove)	^|  (physically insert card)
5680Sstevel@tonic-gate  *			|V
5690Sstevel@tonic-gate  * disconnect	configure
5700Sstevel@tonic-gate  * "-c DISCONNECT"	^|	"-c CONNECT"
5710Sstevel@tonic-gate  *				|V	"-c CONFIGURE"
5720Sstevel@tonic-gate  * connect	unconfigure	->	connect    configure
5730Sstevel@tonic-gate  *						<-
5740Sstevel@tonic-gate  *					"-c UNCONFIGURE"
5750Sstevel@tonic-gate  *
5760Sstevel@tonic-gate  */
5770Sstevel@tonic-gate /*ARGSUSED*/
5780Sstevel@tonic-gate cfga_err_t
5790Sstevel@tonic-gate cfga_change_state(cfga_cmd_t state_change_cmd, const char *ap_id,
5800Sstevel@tonic-gate     const char *options, struct cfga_confirm *confp,
5810Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
5820Sstevel@tonic-gate {
5830Sstevel@tonic-gate 	int rv;
5840Sstevel@tonic-gate 	devctl_hdl_t		dcp;
5850Sstevel@tonic-gate 	devctl_ap_state_t	state;
5860Sstevel@tonic-gate 	ap_rstate_t		rs;
5870Sstevel@tonic-gate 	ap_ostate_t		os;
5880Sstevel@tonic-gate 	hpc_occupant_info_t occupants;
5890Sstevel@tonic-gate 	rcm_handle_t *rhandle;
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
5920Sstevel@tonic-gate 		return (rv);
5930Sstevel@tonic-gate 	}
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate 	if (errstring != NULL)
5960Sstevel@tonic-gate 		*errstring = NULL;
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	rv = CFGA_OK;
5990Sstevel@tonic-gate 	DBG(1, ("cfga_change_state:(%s)\n", ap_id));
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 	if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
6020Sstevel@tonic-gate 		if (rv == EBUSY) {
6030Sstevel@tonic-gate 			cfga_err(errstring, CMD_ACQUIRE, ap_id, 0);
6040Sstevel@tonic-gate 			DBG(1, ("cfga_change_state: device is busy\n"));
6050Sstevel@tonic-gate 			rv = CFGA_BUSY;
6060Sstevel@tonic-gate 		} else
6070Sstevel@tonic-gate 			rv = CFGA_ERROR;
6080Sstevel@tonic-gate 		return (rv);
6090Sstevel@tonic-gate 	}
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
6120Sstevel@tonic-gate 		DBG(2, ("cfga_change_state: devctl ap getstate failed\n"));
6130Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
6140Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
6150Sstevel@tonic-gate 		if (rv == EBUSY)
6160Sstevel@tonic-gate 			rv = CFGA_BUSY;
6170Sstevel@tonic-gate 		else
6180Sstevel@tonic-gate 			rv = CFGA_ERROR;
6190Sstevel@tonic-gate 		return (rv);
6200Sstevel@tonic-gate 	}
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 	rs = state.ap_rstate;
6230Sstevel@tonic-gate 	os = state.ap_ostate;
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate 	DBG(1, ("cfga_change_state: rs is %d\n", state.ap_rstate));
6260Sstevel@tonic-gate 	DBG(1, ("cfga_change_state: os is %d\n", state.ap_ostate));
6270Sstevel@tonic-gate 	switch (state_change_cmd) {
6280Sstevel@tonic-gate 	case CFGA_CMD_CONNECT:
6290Sstevel@tonic-gate 		if ((rs == AP_RSTATE_CONNECTED) ||
6300Sstevel@tonic-gate 		    (os == AP_OSTATE_CONFIGURED)) {
6310Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
6320Sstevel@tonic-gate 			rv = CFGA_INVAL;
6330Sstevel@tonic-gate 		} else {
6340Sstevel@tonic-gate 			/* Lets connect the slot */
6350Sstevel@tonic-gate 			if (devctl_ap_connect(dcp, NULL) == -1) {
6360Sstevel@tonic-gate 				rv = CFGA_ERROR;
6370Sstevel@tonic-gate 				cfga_err(errstring,
6380Sstevel@tonic-gate 				    CMD_SLOT_CONNECT, 0);
6390Sstevel@tonic-gate 			}
6400Sstevel@tonic-gate 		}
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate 		break;
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	case CFGA_CMD_DISCONNECT:
6450Sstevel@tonic-gate 		DBG(1, ("disconnect\n"));
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 		if (os == AP_OSTATE_CONFIGURED) {
6480Sstevel@tonic-gate 			if ((rv = check_rcm(ap_id, &occupants, &rhandle,
6490Sstevel@tonic-gate 			    errstring, flags)) == CFGA_BUSY) {
6500Sstevel@tonic-gate 				break;
6510Sstevel@tonic-gate 			} else if (rv == CFGA_OK) {
6520Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
6530Sstevel@tonic-gate 					if (errno == EBUSY)
6540Sstevel@tonic-gate 						rv = CFGA_BUSY;
6550Sstevel@tonic-gate 					else
6560Sstevel@tonic-gate 						rv = CFGA_ERROR;
6570Sstevel@tonic-gate 					cfga_err(errstring,
6580Sstevel@tonic-gate 					    CMD_SLOT_DISCONNECT, 0);
6590Sstevel@tonic-gate 					fail_rcm(&occupants, rhandle);
6600Sstevel@tonic-gate 					break;
6610Sstevel@tonic-gate 				} else {
6620Sstevel@tonic-gate 					confirm_rcm(&occupants, rhandle);
6630Sstevel@tonic-gate 				}
6640Sstevel@tonic-gate 			} else { /* rv == CFGA_ERROR */
6650Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
6660Sstevel@tonic-gate 					if (errno == EBUSY)
6670Sstevel@tonic-gate 						rv = CFGA_BUSY;
6680Sstevel@tonic-gate 					else
6690Sstevel@tonic-gate 						rv = CFGA_ERROR;
6700Sstevel@tonic-gate 					break;
6710Sstevel@tonic-gate 				} else {
6720Sstevel@tonic-gate 					rv = CFGA_OK;
6730Sstevel@tonic-gate 				}
6740Sstevel@tonic-gate 			}
6750Sstevel@tonic-gate 		}
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate 		if (rs == AP_RSTATE_CONNECTED) {
6780Sstevel@tonic-gate 			if (devctl_ap_disconnect(dcp, NULL) == -1) {
6790Sstevel@tonic-gate 				rv = CFGA_ERROR;
6800Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_DISCONNECT, 0);
6810Sstevel@tonic-gate 				break;
6820Sstevel@tonic-gate 			}
6830Sstevel@tonic-gate 		} else {
6840Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
6850Sstevel@tonic-gate 			rv = CFGA_INVAL;
6860Sstevel@tonic-gate 		}
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate 		break;
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate 	case CFGA_CMD_CONFIGURE:
6910Sstevel@tonic-gate 		if (rs == AP_RSTATE_DISCONNECTED) {
6920Sstevel@tonic-gate 			if (devctl_ap_connect(dcp, NULL) == -1) {
6930Sstevel@tonic-gate 				rv = CFGA_ERROR;
6940Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_CONNECT, 0);
6950Sstevel@tonic-gate 				break;
6960Sstevel@tonic-gate 			}
6970Sstevel@tonic-gate 		}
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate 		/*
7000Sstevel@tonic-gate 		 * for multi-func device we allow multiple
7010Sstevel@tonic-gate 		 * configure on the same slot because one
7020Sstevel@tonic-gate 		 * func can be configured and other one won't
7030Sstevel@tonic-gate 		 */
7040Sstevel@tonic-gate 		if (devctl_ap_configure(dcp, NULL) == -1) {
7050Sstevel@tonic-gate 			rv = CFGA_ERROR;
7060Sstevel@tonic-gate 			cfga_err(errstring, CMD_SLOT_CONFIGURE, 0);
7070Sstevel@tonic-gate 			if (devctl_ap_disconnect(dcp, NULL) == -1) {
7080Sstevel@tonic-gate 				rv = CFGA_ERROR;
7090Sstevel@tonic-gate 				cfga_err(errstring,
7100Sstevel@tonic-gate 				    CMD_SLOT_CONFIGURE, 0);
7110Sstevel@tonic-gate 			}
7120Sstevel@tonic-gate 			break;
7130Sstevel@tonic-gate 		}
7140Sstevel@tonic-gate 
7150Sstevel@tonic-gate 		break;
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	case CFGA_CMD_UNCONFIGURE:
7180Sstevel@tonic-gate 		DBG(1, ("unconfigure\n"));
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 		if (os == AP_OSTATE_CONFIGURED) {
7210Sstevel@tonic-gate 			if ((rv = check_rcm(ap_id, &occupants, &rhandle,
7220Sstevel@tonic-gate 			    errstring, flags)) == CFGA_BUSY) {
7230Sstevel@tonic-gate 				break;
7240Sstevel@tonic-gate 			} else if (rv == CFGA_OK) {
7250Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
7260Sstevel@tonic-gate 					if (errno == EBUSY)
7270Sstevel@tonic-gate 						rv = CFGA_BUSY;
7280Sstevel@tonic-gate 					else {
7290Sstevel@tonic-gate 						if (errno == ENOTSUP)
7300Sstevel@tonic-gate 							rv = CFGA_OPNOTSUPP;
7310Sstevel@tonic-gate 						else
7320Sstevel@tonic-gate 							rv = CFGA_ERROR;
7330Sstevel@tonic-gate 					}
7340Sstevel@tonic-gate 					cfga_err(errstring,
7350Sstevel@tonic-gate 					    CMD_SLOT_UNCONFIGURE, 0);
7360Sstevel@tonic-gate 					fail_rcm(&occupants, rhandle);
7370Sstevel@tonic-gate 				} else {
7380Sstevel@tonic-gate 					confirm_rcm(&occupants, rhandle);
7390Sstevel@tonic-gate 				}
7400Sstevel@tonic-gate 			} else { /* rv == CFGA_ERROR */
7410Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
7420Sstevel@tonic-gate 					if (errno == EBUSY)
7430Sstevel@tonic-gate 						rv = CFGA_BUSY;
7440Sstevel@tonic-gate 					else {
7450Sstevel@tonic-gate 						if (errno == ENOTSUP)
7460Sstevel@tonic-gate 							rv = CFGA_OPNOTSUPP;
7470Sstevel@tonic-gate 						else
7480Sstevel@tonic-gate 							rv = CFGA_ERROR;
7490Sstevel@tonic-gate 					}
7500Sstevel@tonic-gate 					cfga_err(errstring,
7510Sstevel@tonic-gate 					    CMD_SLOT_UNCONFIGURE, 0);
7520Sstevel@tonic-gate 				} else {
7530Sstevel@tonic-gate 					rv = CFGA_OK;
7540Sstevel@tonic-gate 				}
7550Sstevel@tonic-gate 			}
7560Sstevel@tonic-gate 		} else {
7570Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
7580Sstevel@tonic-gate 			rv = CFGA_INVAL;
7590Sstevel@tonic-gate 		}
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate 		DBG(1, ("uncofigure rv:(%i)\n", rv));
7620Sstevel@tonic-gate 		break;
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate 	case CFGA_CMD_LOAD:
7650Sstevel@tonic-gate 		if ((os == AP_OSTATE_UNCONFIGURED) &&
7660Sstevel@tonic-gate 		    (rs == AP_RSTATE_DISCONNECTED)) {
7670Sstevel@tonic-gate 			if (devctl_ap_insert(dcp, NULL) == -1) {
7680Sstevel@tonic-gate 				rv = CFGA_ERROR;
7690Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_INSERT, 0);
7700Sstevel@tonic-gate 			}
7710Sstevel@tonic-gate 		} else {
7720Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
7730Sstevel@tonic-gate 			rv = CFGA_INVAL;
7740Sstevel@tonic-gate 		}
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 		break;
7770Sstevel@tonic-gate 
7780Sstevel@tonic-gate 	case CFGA_CMD_UNLOAD:
7790Sstevel@tonic-gate 		if ((os == AP_OSTATE_UNCONFIGURED) &&
7800Sstevel@tonic-gate 		    (rs == AP_RSTATE_DISCONNECTED)) {
7810Sstevel@tonic-gate 			if (devctl_ap_remove(dcp, NULL) == -1) {
7820Sstevel@tonic-gate 				rv = CFGA_ERROR;
7830Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_REMOVE, 0);
7840Sstevel@tonic-gate 			}
7850Sstevel@tonic-gate 		} else {
7860Sstevel@tonic-gate 				cfga_err(errstring, ERR_AP_ERR, 0);
7870Sstevel@tonic-gate 				rv = CFGA_INVAL;
7880Sstevel@tonic-gate 			}
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate 		break;
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate 	default:
7930Sstevel@tonic-gate 		rv = CFGA_OPNOTSUPP;
7940Sstevel@tonic-gate 		break;
7950Sstevel@tonic-gate 	}
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate 	devctl_release((devctl_hdl_t)dcp);
7980Sstevel@tonic-gate 	return (rv);
7990Sstevel@tonic-gate }
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate /*
8020Sstevel@tonic-gate  * Building iocdatat to pass it to nexus
8030Sstevel@tonic-gate  *
8040Sstevel@tonic-gate  *	iocdata->cmd ==  HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT
8050Sstevel@tonic-gate  *			HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG
8060Sstevel@tonic-gate  *			HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE
8070Sstevel@tonic-gate  *			HPC_CTRL_GET_SLOT_STATE/HPC_CTRL_GET_SLOT_INFO
8080Sstevel@tonic-gate  *			HPC_CTRL_DEV_CONFIGURE/HPC_CTRL_DEV_UNCONFIGURE
8090Sstevel@tonic-gate  *			HPC_CTRL_GET_BOARD_TYPE
8100Sstevel@tonic-gate  *
8110Sstevel@tonic-gate  */
8120Sstevel@tonic-gate static void
8130Sstevel@tonic-gate build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
8140Sstevel@tonic-gate     void *retdata)
8150Sstevel@tonic-gate {
8160Sstevel@tonic-gate 	iocdata->cmd = cmd;
8170Sstevel@tonic-gate 	iocdata->data = retdata;
8180Sstevel@tonic-gate }
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate /*
8210Sstevel@tonic-gate  * building logical name from ap_id
8220Sstevel@tonic-gate  */
8230Sstevel@tonic-gate /*ARGSUSED2*/
8240Sstevel@tonic-gate static void
8250Sstevel@tonic-gate get_logical_name(const char *ap_id, char *buf, dev_t rdev)
8260Sstevel@tonic-gate {
8270Sstevel@tonic-gate 	char *bufptr, *bufptr2, *pci, *apid;
8280Sstevel@tonic-gate 
8290Sstevel@tonic-gate 	DBG(1, ("get_logical_name: %s\n", ap_id));
8300Sstevel@tonic-gate 
8310Sstevel@tonic-gate 	if ((apid = malloc(MAXPATHLEN)) == NULL) {
8320Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
8330Sstevel@tonic-gate 		return;
8340Sstevel@tonic-gate 	}
8350Sstevel@tonic-gate 
8360Sstevel@tonic-gate 	(void) memset(apid, 0, MAXPATHLEN);
8370Sstevel@tonic-gate 	(void) strncpy(apid, ap_id, strlen(ap_id));
8380Sstevel@tonic-gate 
8390Sstevel@tonic-gate 	/* needs to look for last /, not first */
8400Sstevel@tonic-gate 	bufptr = strrchr(apid, '/');
8410Sstevel@tonic-gate 
8420Sstevel@tonic-gate 	bufptr2 = strrchr(apid, ':');
8430Sstevel@tonic-gate 	pci = ++bufptr;
8440Sstevel@tonic-gate 	bufptr = strchr(pci, ',');
8450Sstevel@tonic-gate 	if (bufptr != NULL) {
8460Sstevel@tonic-gate 		*bufptr = '\0';
8470Sstevel@tonic-gate 	}
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate 	bufptr = strchr(pci, '@');
8500Sstevel@tonic-gate 	if (bufptr != NULL) {
8510Sstevel@tonic-gate 		*bufptr = '\0';
8520Sstevel@tonic-gate 		bufptr++;
8530Sstevel@tonic-gate 	}
8540Sstevel@tonic-gate 
8550Sstevel@tonic-gate 	DBG(1, ("%s\n%s\n%s\n", pci, bufptr, bufptr2));
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate 	(void) strcat(buf, pci);
8580Sstevel@tonic-gate 	(void) strcat(buf, bufptr);
8590Sstevel@tonic-gate 	(void) strcat(buf, bufptr2);
8600Sstevel@tonic-gate 	free(apid);
8610Sstevel@tonic-gate }
8620Sstevel@tonic-gate 
8630Sstevel@tonic-gate static cfga_err_t
8640Sstevel@tonic-gate prt_led_mode(const char *ap_id, int repeat, char **errstring,
8650Sstevel@tonic-gate     struct cfga_msg *msgp)
8660Sstevel@tonic-gate {
8670Sstevel@tonic-gate 	hpc_led_info_t	power_led_info = {HPC_POWER_LED, 0};
8680Sstevel@tonic-gate 	hpc_led_info_t	fault_led_info = {HPC_FAULT_LED, 0};
8690Sstevel@tonic-gate 	hpc_led_info_t	attn_led_info = {HPC_ATTN_LED, 0};
8700Sstevel@tonic-gate 	hpc_led_info_t	active_led_info = {HPC_ACTIVE_LED, 0};
8710Sstevel@tonic-gate 	struct hpc_control_data iocdata;
8720Sstevel@tonic-gate 	struct stat	statbuf;
8730Sstevel@tonic-gate 	char  *buff;
8740Sstevel@tonic-gate 	int	fd;
8750Sstevel@tonic-gate 	hpc_slot_info_t		slot_info;
8760Sstevel@tonic-gate 	char *cp, line[MAXLINE];
8770Sstevel@tonic-gate 	int len = MAXLINE;
8780Sstevel@tonic-gate 
8790Sstevel@tonic-gate 	DBG(1, ("prt_led_mod function\n"));
8800Sstevel@tonic-gate 	if (!repeat)
8810Sstevel@tonic-gate 		cfga_msg(msgp, "Ap_Id\t\t\tLed");
8820Sstevel@tonic-gate 
8830Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
8840Sstevel@tonic-gate 		DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
8850Sstevel@tonic-gate 		DBG_F(2, (stderr, "open on %s failed\n", ap_id));
8860Sstevel@tonic-gate 		cfga_err(errstring, CMD_OPEN,  ap_id, 0);
8870Sstevel@tonic-gate 		return (CFGA_ERROR);
8880Sstevel@tonic-gate 	}
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate 	if (fstat(fd, &statbuf) == -1) {
8910Sstevel@tonic-gate 		DBG(2, ("fstat = ap_id%s, fd%d\n", ap_id, fd));
8920Sstevel@tonic-gate 		DBG_F(2, (stderr, "fstat on %s failed\n", ap_id));
8930Sstevel@tonic-gate 		cfga_err(errstring, CMD_FSTAT, ap_id, 0);
8940Sstevel@tonic-gate 		return (CFGA_ERROR);
8950Sstevel@tonic-gate 	}
8960Sstevel@tonic-gate 
8970Sstevel@tonic-gate 	if ((buff = malloc(MAXPATHLEN)) == NULL) {
8980Sstevel@tonic-gate 		cfga_err(errstring, "malloc ", 0);
8990Sstevel@tonic-gate 		return (CFGA_ERROR);
9000Sstevel@tonic-gate 	}
9010Sstevel@tonic-gate 
9020Sstevel@tonic-gate 	(void) memset(buff, 0, MAXPATHLEN);
9030Sstevel@tonic-gate 
9040Sstevel@tonic-gate 	DBG(1, ("ioctl boardtype\n"));
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
9070Sstevel@tonic-gate 	    (void *)&slot_info);
9080Sstevel@tonic-gate 
9090Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9100Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
9110Sstevel@tonic-gate 		DBG(1, ("ioctl failed slotinfo: %s\n",
9120Sstevel@tonic-gate 		    slot_info.pci_slot_name));
9130Sstevel@tonic-gate 	} else {
9140Sstevel@tonic-gate 
9150Sstevel@tonic-gate 		/*
9160Sstevel@tonic-gate 		 * the driver will report back things like hpc0_slot0
9170Sstevel@tonic-gate 		 * this needs to be changed to things like pci1:hpc0_slot0
9180Sstevel@tonic-gate 		 */
9190Sstevel@tonic-gate 		if (fix_ap_name(buff, ap_id, slot_info.pci_slot_name,
9200Sstevel@tonic-gate 		    errstring) != CFGA_OK) {
9210Sstevel@tonic-gate 			free(buff);
9220Sstevel@tonic-gate 			(void) close(fd);
9230Sstevel@tonic-gate 			return (CFGA_ERROR);
9240Sstevel@tonic-gate 		}
9250Sstevel@tonic-gate 		DBG(1, ("ioctl slotinfo: %s\n", buff));
9260Sstevel@tonic-gate 	}
9270Sstevel@tonic-gate 
9280Sstevel@tonic-gate 	cp = line;
9290Sstevel@tonic-gate 	(void) snprintf(cp, len, "%s\t\t", buff);
9300Sstevel@tonic-gate 	len -= strlen(cp);
9310Sstevel@tonic-gate 	cp += strlen(cp);
9320Sstevel@tonic-gate 
9330Sstevel@tonic-gate 	free(buff);
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &power_led_info);
9360Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9370Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9380Sstevel@tonic-gate 		    led_strs[power_led_info.led], cfga_strs[UNKNOWN]);
9390Sstevel@tonic-gate 		len -= strlen(cp);
9400Sstevel@tonic-gate 		cp += strlen(cp);
9410Sstevel@tonic-gate 	} else {
9420Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,", led_strs[power_led_info.led],
9430Sstevel@tonic-gate 		    mode_strs[power_led_info.state]);
9440Sstevel@tonic-gate 		len -= strlen(cp);
9450Sstevel@tonic-gate 		cp += strlen(cp);
9460Sstevel@tonic-gate 	}
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[power_led_info.led], power_led_info.state));
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &fault_led_info);
9510Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9520Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9530Sstevel@tonic-gate 		    led_strs[fault_led_info.led], cfga_strs[UNKNOWN]);
9540Sstevel@tonic-gate 		len -= strlen(cp);
9550Sstevel@tonic-gate 		cp += strlen(cp);
9560Sstevel@tonic-gate 	} else {
9570Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9580Sstevel@tonic-gate 		    led_strs[fault_led_info.led],
9590Sstevel@tonic-gate 		    mode_strs[fault_led_info.state]);
9600Sstevel@tonic-gate 		len -= strlen(cp);
9610Sstevel@tonic-gate 		cp += strlen(cp);
9620Sstevel@tonic-gate 	}
9630Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[fault_led_info.led], fault_led_info.state));
9640Sstevel@tonic-gate 
9650Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &attn_led_info);
9660Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9670Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9680Sstevel@tonic-gate 		    led_strs[attn_led_info.led], cfga_strs[UNKNOWN]);
9690Sstevel@tonic-gate 		len -= strlen(cp);
9700Sstevel@tonic-gate 		cp += strlen(cp);
9710Sstevel@tonic-gate 	} else {
9720Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9730Sstevel@tonic-gate 		    led_strs[attn_led_info.led],
9740Sstevel@tonic-gate 		    mode_strs[attn_led_info.state]);
9750Sstevel@tonic-gate 		len -= strlen(cp);
9760Sstevel@tonic-gate 		cp += strlen(cp);
9770Sstevel@tonic-gate 	}
9780Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[attn_led_info.led], attn_led_info.state));
9790Sstevel@tonic-gate 
9800Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &active_led_info);
9810Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9820Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s", led_strs[active_led_info.led],
9830Sstevel@tonic-gate 		    cfga_strs[UNKNOWN]);
9840Sstevel@tonic-gate 	} else {
9850Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s",
9860Sstevel@tonic-gate 		    led_strs[active_led_info.led],
9870Sstevel@tonic-gate 		    mode_strs[active_led_info.state]);
9880Sstevel@tonic-gate 	}
9890Sstevel@tonic-gate 	cfga_msg(msgp, line);	/* print the message */
9900Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[active_led_info.led],
9910Sstevel@tonic-gate 	    active_led_info.state));
9920Sstevel@tonic-gate 
9930Sstevel@tonic-gate 	(void) close(fd);
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate 	return (CFGA_OK);
9960Sstevel@tonic-gate }
9970Sstevel@tonic-gate 
9980Sstevel@tonic-gate /*ARGSUSED*/
9990Sstevel@tonic-gate cfga_err_t
10000Sstevel@tonic-gate cfga_private_func(const char *function, const char *ap_id,
10010Sstevel@tonic-gate     const char *options, struct cfga_confirm *confp,
10020Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
10030Sstevel@tonic-gate {
10040Sstevel@tonic-gate 	char *str;
10050Sstevel@tonic-gate 	int   len, fd, i = 0, repeat = 0;
10060Sstevel@tonic-gate 	char buf[MAXNAMELEN];
10070Sstevel@tonic-gate 	char ptr;
10080Sstevel@tonic-gate 	hpc_led_info_t	led_info;
10090Sstevel@tonic-gate 	struct hpc_control_data	iocdata;
10100Sstevel@tonic-gate 	cfga_err_t rv;
10110Sstevel@tonic-gate 
10120Sstevel@tonic-gate 	DBG(1, ("cfgadm_private_func: ap_id:%s\n", ap_id));
10130Sstevel@tonic-gate 	DBG(2, ("  options: %s\n", (options == NULL)?"null":options));
10140Sstevel@tonic-gate 	DBG(2, ("  confp: %x\n", confp));
10150Sstevel@tonic-gate 	DBG(2, ("  cfga_msg: %x\n", cfga_msg));
10160Sstevel@tonic-gate 	DBG(2, ("  flag: %d\n", flags));
10170Sstevel@tonic-gate 
10180Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
10190Sstevel@tonic-gate 		return (rv);
10200Sstevel@tonic-gate 	}
10210Sstevel@tonic-gate 
10220Sstevel@tonic-gate 	if (private_check == confp)
10230Sstevel@tonic-gate 		repeat = 1;
10240Sstevel@tonic-gate 	else
10250Sstevel@tonic-gate 		private_check = (void*)confp;
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate 	/* XXX change const 6 to func_str[i] != NULL */
10280Sstevel@tonic-gate 	for (i = 0, str = func_strs[i], len = strlen(str); i < 6; i++) {
10290Sstevel@tonic-gate 		str = func_strs[i];
10300Sstevel@tonic-gate 		len = strlen(str);
10310Sstevel@tonic-gate 		if (strncmp(function, str, len) == 0)
10320Sstevel@tonic-gate 			break;
10330Sstevel@tonic-gate 	}
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 	switch (i) {
10360Sstevel@tonic-gate 		case ENABLE_SLOT:
10370Sstevel@tonic-gate 			build_control_data(&iocdata,
10380Sstevel@tonic-gate 				HPC_CTRL_ENABLE_SLOT, 0);
10390Sstevel@tonic-gate 			break;
10400Sstevel@tonic-gate 		case DISABLE_SLOT:
10410Sstevel@tonic-gate 			build_control_data(&iocdata,
10420Sstevel@tonic-gate 				HPC_CTRL_DISABLE_SLOT, 0);
10430Sstevel@tonic-gate 			break;
10440Sstevel@tonic-gate 		case ENABLE_AUTOCNF:
10450Sstevel@tonic-gate 			build_control_data(&iocdata,
10460Sstevel@tonic-gate 				HPC_CTRL_ENABLE_AUTOCFG, 0);
10470Sstevel@tonic-gate 			break;
10480Sstevel@tonic-gate 		case DISABLE_AUTOCNF:
10490Sstevel@tonic-gate 			build_control_data(&iocdata,
10500Sstevel@tonic-gate 				HPC_CTRL_DISABLE_AUTOCFG, 0);
10510Sstevel@tonic-gate 			break;
10520Sstevel@tonic-gate 		case LED:
10530Sstevel@tonic-gate 			/* set mode */
10540Sstevel@tonic-gate 			ptr = function[len++];
10550Sstevel@tonic-gate 			if (ptr == '=') {
10560Sstevel@tonic-gate 				str = (char *)function;
10570Sstevel@tonic-gate 				for (str = (str+len++), i = 0; *str != ',';
10580Sstevel@tonic-gate 				    i++, str++) {
10590Sstevel@tonic-gate 					if (i == (MAXNAMELEN - 1))
10600Sstevel@tonic-gate 						break;
10610Sstevel@tonic-gate 
10620Sstevel@tonic-gate 					buf[i] = *str;
10630Sstevel@tonic-gate 					DBG_F(2, (stdout, "%c\n", buf[i]));
10640Sstevel@tonic-gate 				}
10650Sstevel@tonic-gate 				buf[i] = '\0'; str++;
10660Sstevel@tonic-gate 				DBG(2, ("buf = %s\n", buf));
10670Sstevel@tonic-gate 
10680Sstevel@tonic-gate 				/* ACTIVE=3,ATTN=2,POWER=1,FAULT=0 */
10690Sstevel@tonic-gate 				if (strcmp(buf, led_strs[POWER]) == 0)
10700Sstevel@tonic-gate 					led_info.led = HPC_POWER_LED;
10710Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[FAULT]) == 0)
10720Sstevel@tonic-gate 					led_info.led = HPC_FAULT_LED;
10730Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[ATTN]) == 0)
10740Sstevel@tonic-gate 					led_info.led = HPC_ATTN_LED;
10750Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[ACTIVE]) == 0)
10760Sstevel@tonic-gate 					led_info.led = HPC_ACTIVE_LED;
10770Sstevel@tonic-gate 				else return (CFGA_INVAL);
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate 				len = strlen(func_strs[MODE]);
10800Sstevel@tonic-gate 				if ((strncmp(str, func_strs[MODE], len) == 0) &&
10810Sstevel@tonic-gate 				    (*(str+(len)) == '=')) {
10820Sstevel@tonic-gate 				    for (str = (str+(++len)), i = 0;
10830Sstevel@tonic-gate 					*str != NULL; i++, str++) {
10840Sstevel@tonic-gate 						buf[i] = *str;
10850Sstevel@tonic-gate 
10860Sstevel@tonic-gate 				    }
10870Sstevel@tonic-gate 				}
10880Sstevel@tonic-gate 				buf[i] = '\0';
10890Sstevel@tonic-gate 				DBG(2, ("buf_mode= %s\n", buf));
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate 				/* ON = 1, OFF = 0 */
10920Sstevel@tonic-gate 				if (strcmp(buf, mode_strs[ON]) == 0)
10930Sstevel@tonic-gate 					led_info.state = HPC_LED_ON;
10940Sstevel@tonic-gate 				else if (strcmp(buf, mode_strs[OFF]) == 0)
10950Sstevel@tonic-gate 					led_info.state = HPC_LED_OFF;
10960Sstevel@tonic-gate 				else if (strcmp(buf, mode_strs[BLINK]) == 0)
10970Sstevel@tonic-gate 					led_info.state = HPC_LED_BLINK;
10980Sstevel@tonic-gate 				else return (CFGA_INVAL);
10990Sstevel@tonic-gate 
11000Sstevel@tonic-gate 				/* sendin  */
11010Sstevel@tonic-gate 				build_control_data(&iocdata,
11020Sstevel@tonic-gate 				    HPC_CTRL_SET_LED_STATE,
11030Sstevel@tonic-gate 				    (void *)&led_info);
11040Sstevel@tonic-gate 				break;
11050Sstevel@tonic-gate 			} else if (ptr == '\0') {
11060Sstevel@tonic-gate 				/* print mode */
11070Sstevel@tonic-gate 				DBG(1, ("Print mode\n"));
11080Sstevel@tonic-gate 				return (prt_led_mode(ap_id, repeat, errstring,
11090Sstevel@tonic-gate 				    msgp));
11100Sstevel@tonic-gate 			}
11110Sstevel@tonic-gate 		default:
11120Sstevel@tonic-gate 			DBG(1, ("default\n"));
11130Sstevel@tonic-gate 			errno = EINVAL;
11140Sstevel@tonic-gate 			return (CFGA_INVAL);
11150Sstevel@tonic-gate 	}
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
11180Sstevel@tonic-gate 		DBG(1, ("open failed\n"));
11190Sstevel@tonic-gate 		return (CFGA_ERROR);
11200Sstevel@tonic-gate 	}
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate 	DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
11230Sstevel@tonic-gate 
11240Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
11250Sstevel@tonic-gate 		DBG(1, ("ioctl failed\n"));
11260Sstevel@tonic-gate 		(void) close(fd);
11270Sstevel@tonic-gate 		return (CFGA_ERROR);
11280Sstevel@tonic-gate 	}
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate 	(void) close(fd);
11310Sstevel@tonic-gate 
11320Sstevel@tonic-gate 	return (CFGA_OK);
11330Sstevel@tonic-gate }
11340Sstevel@tonic-gate 
11350Sstevel@tonic-gate /*ARGSUSED*/
11360Sstevel@tonic-gate cfga_err_t cfga_test(const char *ap_id, const char *options,
11370Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
11380Sstevel@tonic-gate {
11390Sstevel@tonic-gate 	cfga_err_t rv;
11400Sstevel@tonic-gate 	if (errstring != NULL)
11410Sstevel@tonic-gate 		*errstring = NULL;
11420Sstevel@tonic-gate 
11430Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
11440Sstevel@tonic-gate 		return (rv);
11450Sstevel@tonic-gate 	}
11460Sstevel@tonic-gate 
11470Sstevel@tonic-gate 	DBG(1, ("cfga_test:(%s)\n", ap_id));
11480Sstevel@tonic-gate 	/* will need to implement pci CTRL command */
11490Sstevel@tonic-gate 	return (CFGA_NOTSUPP);
11500Sstevel@tonic-gate }
11510Sstevel@tonic-gate 
11520Sstevel@tonic-gate static int
11530Sstevel@tonic-gate fixup_slotname(int rval, int *intp, struct searcharg *slotarg)
11540Sstevel@tonic-gate {
11550Sstevel@tonic-gate 
11560Sstevel@tonic-gate /*
11570Sstevel@tonic-gate  * The slot-names property describes the external labeling of add-in slots.
11580Sstevel@tonic-gate  * This property is an encoded array, an integer followed by a list of
11590Sstevel@tonic-gate  * strings. The return value from di_prop_lookup_ints for slot-names is -1.
11600Sstevel@tonic-gate  * The expected return value should be the number of elements.
11610Sstevel@tonic-gate  * Di_prop_decode_common does not decode encoded data from software,
11620Sstevel@tonic-gate  * such as the solaris device tree, unlike from the prom.
11630Sstevel@tonic-gate  * Di_prop_decode_common takes the size of the encoded data and mods
11640Sstevel@tonic-gate  * it with the size of int. The size of the encoded data for slot-names is 9
11650Sstevel@tonic-gate  * and the size of int is 4, yielding a non zero result. A value of -1 is used
11660Sstevel@tonic-gate  * to indicate that the number of elements can not be determined.
11670Sstevel@tonic-gate  * Di_prop_decode_common can be modified to decode encoded data from the solaris
11680Sstevel@tonic-gate  * device tree.
11690Sstevel@tonic-gate  */
11700Sstevel@tonic-gate 
11710Sstevel@tonic-gate 	if ((slotarg->slt_name_src == PROM_SLT_NAME) && (rval == -1)) {
11720Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
11730Sstevel@tonic-gate 	} else {
11740Sstevel@tonic-gate 		int i;
11750Sstevel@tonic-gate 		char *tmptr = (char *)(intp+1);
11760Sstevel@tonic-gate 		DBG(1, ("slot-bitmask: %x \n", *intp));
11770Sstevel@tonic-gate 
11780Sstevel@tonic-gate 		rval = (rval -1) * 4;
11790Sstevel@tonic-gate 
11800Sstevel@tonic-gate 		for (i = 0; i <= slotarg->minor; i++) {
11810Sstevel@tonic-gate 			DBG(2, ("curr slot-name: %s \n", tmptr));
11820Sstevel@tonic-gate 
11830Sstevel@tonic-gate 			if (i >= MAXDEVS)
11840Sstevel@tonic-gate 				return (DI_WALK_TERMINATE);
11850Sstevel@tonic-gate 
11860Sstevel@tonic-gate 			if ((*intp >> i) & 1) {
11870Sstevel@tonic-gate 				/* assign tmptr */
11880Sstevel@tonic-gate 				DBG(2, ("slot-name: %s \n", tmptr));
11890Sstevel@tonic-gate 				if (i == slotarg->minor)
11900Sstevel@tonic-gate 					(void) strcpy(slotarg->slotnames[i],
11910Sstevel@tonic-gate 					    tmptr);
11920Sstevel@tonic-gate 				/* wind tmptr to next \0 */
11930Sstevel@tonic-gate 				while (*tmptr != '\0') {
11940Sstevel@tonic-gate 					tmptr++;
11950Sstevel@tonic-gate 				}
11960Sstevel@tonic-gate 				tmptr++;
11970Sstevel@tonic-gate 			} else {
11980Sstevel@tonic-gate 				/* point at unknown string */
11990Sstevel@tonic-gate 				if (i == slotarg->minor)
12000Sstevel@tonic-gate 					(void) strcpy(slotarg->slotnames[i],
12010Sstevel@tonic-gate 					    "unknown");
12020Sstevel@tonic-gate 			}
12030Sstevel@tonic-gate 		}
12040Sstevel@tonic-gate 	}
12050Sstevel@tonic-gate 	return (DI_WALK_TERMINATE);
12060Sstevel@tonic-gate }
12070Sstevel@tonic-gate 
12080Sstevel@tonic-gate static int
12090Sstevel@tonic-gate find_slotname(di_node_t din, di_minor_t dim, void *arg)
12100Sstevel@tonic-gate {
12110Sstevel@tonic-gate 	struct searcharg *slotarg = (struct searcharg *)arg;
12120Sstevel@tonic-gate 	di_prom_handle_t ph = (di_prom_handle_t)slotarg->promp;
12130Sstevel@tonic-gate 	di_prom_prop_t	prom_prop;
12140Sstevel@tonic-gate 	di_prop_t	solaris_prop;
12150Sstevel@tonic-gate 	int *intp, rval;
12160Sstevel@tonic-gate 	char *devname;
12170Sstevel@tonic-gate 	char fulldevname[MAXNAMELEN];
12180Sstevel@tonic-gate 
12190Sstevel@tonic-gate 	slotarg->minor = dim->dev_minor % 256;
12200Sstevel@tonic-gate 
12210Sstevel@tonic-gate 	DBG(2, ("minor number:(%i)\n", slotarg->minor));
12220Sstevel@tonic-gate 	DBG(2, ("hot plug slots found so far:(%i)\n", 0));
12230Sstevel@tonic-gate 
12240Sstevel@tonic-gate 	if ((devname = di_devfs_path(din)) != NULL) {
12250Sstevel@tonic-gate 		(void) snprintf(fulldevname, MAXNAMELEN,
12260Sstevel@tonic-gate 		    "/devices%s:%s", devname, di_minor_name(dim));
12270Sstevel@tonic-gate 		di_devfs_path_free(devname);
12280Sstevel@tonic-gate 	}
12290Sstevel@tonic-gate 
12300Sstevel@tonic-gate 	if (strcmp(fulldevname, slotarg->devpath) == 0) {
12310Sstevel@tonic-gate 
12320Sstevel@tonic-gate 		/*
12330Sstevel@tonic-gate 		 * Check the Solaris device tree first
12340Sstevel@tonic-gate 		 * in the case of a DR operation
12350Sstevel@tonic-gate 		 */
12360Sstevel@tonic-gate 		solaris_prop = di_prop_hw_next(din, DI_PROP_NIL);
12370Sstevel@tonic-gate 		while (solaris_prop != DI_PROP_NIL) {
12380Sstevel@tonic-gate 			if (strcmp("slot-names", di_prop_name(solaris_prop))
12390Sstevel@tonic-gate 			    == 0) {
12400Sstevel@tonic-gate 				rval = di_prop_lookup_ints(DDI_DEV_T_ANY,
12410Sstevel@tonic-gate 				    din, di_prop_name(solaris_prop), &intp);
12420Sstevel@tonic-gate 				slotarg->slt_name_src = SOLARIS_SLT_NAME;
12430Sstevel@tonic-gate 
12440Sstevel@tonic-gate 				return (fixup_slotname(rval, intp, slotarg));
12450Sstevel@tonic-gate 			}
12460Sstevel@tonic-gate 			solaris_prop = di_prop_hw_next(din, solaris_prop);
12470Sstevel@tonic-gate 		}
12480Sstevel@tonic-gate 
12490Sstevel@tonic-gate 		/*
12500Sstevel@tonic-gate 		 * Check the prom device tree which is populated at boot.
12510Sstevel@tonic-gate 		 * If this fails, give up and set the slot name to null.
12520Sstevel@tonic-gate 		 */
12530Sstevel@tonic-gate 		prom_prop = di_prom_prop_next(ph, din, DI_PROM_PROP_NIL);
12540Sstevel@tonic-gate 		while (prom_prop != DI_PROM_PROP_NIL) {
12550Sstevel@tonic-gate 			if (strcmp("slot-names", di_prom_prop_name(prom_prop))
12560Sstevel@tonic-gate 			    == 0) {
12570Sstevel@tonic-gate 				rval = di_prom_prop_lookup_ints(ph,
12580Sstevel@tonic-gate 				    din, di_prom_prop_name(prom_prop), &intp);
12590Sstevel@tonic-gate 				slotarg->slt_name_src = PROM_SLT_NAME;
12600Sstevel@tonic-gate 
12610Sstevel@tonic-gate 				return (fixup_slotname(rval, intp, slotarg));
12620Sstevel@tonic-gate 			}
12630Sstevel@tonic-gate 			prom_prop = di_prom_prop_next(ph, din, prom_prop);
12640Sstevel@tonic-gate 		}
12650Sstevel@tonic-gate 		*slotarg->slotnames[slotarg->minor] = '\0';
12660Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
12670Sstevel@tonic-gate 	} else
12680Sstevel@tonic-gate 		return (DI_WALK_CONTINUE);
12690Sstevel@tonic-gate }
12700Sstevel@tonic-gate 
12710Sstevel@tonic-gate static int
12720Sstevel@tonic-gate find_physical_slot_names(const char *devcomp, struct searcharg *slotarg)
12730Sstevel@tonic-gate {
12740Sstevel@tonic-gate 	di_node_t root_node;
12750Sstevel@tonic-gate 
12760Sstevel@tonic-gate 	DBG(1, ("find_physical_slot_names\n"));
12770Sstevel@tonic-gate 
12780Sstevel@tonic-gate 	if ((root_node = di_init("/", DINFOCPYALL|DINFOPATH))
12790Sstevel@tonic-gate 		== DI_NODE_NIL) {
12800Sstevel@tonic-gate 		DBG(1, ("di_init() failed\n"));
12810Sstevel@tonic-gate 		return (NULL);
12820Sstevel@tonic-gate 	}
12830Sstevel@tonic-gate 
12840Sstevel@tonic-gate 	slotarg->devpath = (char *)devcomp;
12850Sstevel@tonic-gate 
12860Sstevel@tonic-gate 	if ((slotarg->promp = di_prom_init()) == DI_PROM_HANDLE_NIL) {
12870Sstevel@tonic-gate 		DBG(1, ("di_prom_init() failed\n"));
12880Sstevel@tonic-gate 		di_fini(root_node);
12890Sstevel@tonic-gate 		return (NULL);
12900Sstevel@tonic-gate 	}
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 	(void) di_walk_minor(root_node, "ddi_ctl:attachment_point:pci",
12930Sstevel@tonic-gate 		0, (void *)slotarg, find_slotname);
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 	di_prom_fini(slotarg->promp);
12960Sstevel@tonic-gate 	di_fini(root_node);
12970Sstevel@tonic-gate 	if (slotarg->slotnames[0] != NULL)
12980Sstevel@tonic-gate 		return (0);
12990Sstevel@tonic-gate 	else
13000Sstevel@tonic-gate 		return (-1);
13010Sstevel@tonic-gate }
13020Sstevel@tonic-gate 
13030Sstevel@tonic-gate static void
13040Sstevel@tonic-gate get_type(hpc_board_type_t boardtype, hpc_card_info_t cardinfo, char *buf)
13050Sstevel@tonic-gate {
1306*58Sanish 	int i;
13070Sstevel@tonic-gate 
13080Sstevel@tonic-gate 	DBG(1, ("class: %i\n", cardinfo.base_class));
13090Sstevel@tonic-gate 	DBG(1, ("subclass: %i\n", cardinfo.sub_class));
13100Sstevel@tonic-gate 
13110Sstevel@tonic-gate 	if (cardinfo.base_class == PCI_CLASS_NONE) {
13120Sstevel@tonic-gate 		TPCT("unknown");
13130Sstevel@tonic-gate 		return;
13140Sstevel@tonic-gate 	}
13150Sstevel@tonic-gate 
1316*58Sanish 	for (i = 0; i < class_pci_items; i++) {
1317*58Sanish 		if ((cardinfo.base_class == class_pci[i].base_class) &&
1318*58Sanish 		    (cardinfo.sub_class == class_pci[i].sub_class) &&
1319*58Sanish 		    (cardinfo.prog_class == class_pci[i].prog_class)) {
1320*58Sanish 			TPCT(class_pci[i].short_desc);
1321*58Sanish 			break;
13220Sstevel@tonic-gate 		}
13230Sstevel@tonic-gate 	}
13240Sstevel@tonic-gate 
1325*58Sanish 	if (i == class_pci_items)
1326*58Sanish 		TPCT("unknown");
1327*58Sanish 
13280Sstevel@tonic-gate 	TPCT("/");
13290Sstevel@tonic-gate 	switch (boardtype) {
13300Sstevel@tonic-gate 	case HPC_BOARD_PCI_HOTPLUG:
13310Sstevel@tonic-gate 	case HPC_BOARD_CPCI_NON_HS:
13320Sstevel@tonic-gate 	case HPC_BOARD_CPCI_BASIC_HS:
13330Sstevel@tonic-gate 	case HPC_BOARD_CPCI_FULL_HS:
13340Sstevel@tonic-gate 	case HPC_BOARD_CPCI_HS:
13350Sstevel@tonic-gate 		TPCT(board_strs[boardtype]);
13360Sstevel@tonic-gate 		break;
13370Sstevel@tonic-gate 	case HPC_BOARD_UNKNOWN:
13380Sstevel@tonic-gate 	default:
13390Sstevel@tonic-gate 		TPCT(board_strs[HPC_BOARD_UNKNOWN]);
13400Sstevel@tonic-gate 	}
13410Sstevel@tonic-gate }
13420Sstevel@tonic-gate 
13430Sstevel@tonic-gate /*
13440Sstevel@tonic-gate  * call-back function for di_devlink_walk
13450Sstevel@tonic-gate  * if the link lives in /dev/cfg copy its name
13460Sstevel@tonic-gate  */
13470Sstevel@tonic-gate static int
13480Sstevel@tonic-gate found_devlink(di_devlink_t link, void *ap_log_id)
13490Sstevel@tonic-gate {
13500Sstevel@tonic-gate 	if (strncmp("/dev/cfg/", di_devlink_path(link), 9) == 0) {
13510Sstevel@tonic-gate 		/* copy everything but /dev/cfg/ */
13520Sstevel@tonic-gate 		(void) strcpy((char *)ap_log_id, di_devlink_path(link) + 9);
13530Sstevel@tonic-gate 		DBG(1, ("found_devlink: %s\n", (char *)ap_log_id));
13540Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
13550Sstevel@tonic-gate 	}
13560Sstevel@tonic-gate 	return (DI_WALK_CONTINUE);
13570Sstevel@tonic-gate }
13580Sstevel@tonic-gate 
13590Sstevel@tonic-gate /*
13600Sstevel@tonic-gate  * Walk throught the cached /dev link tree looking for links to the ap
13610Sstevel@tonic-gate  * if none are found return an error
13620Sstevel@tonic-gate  */
13630Sstevel@tonic-gate static cfga_err_t
13640Sstevel@tonic-gate check_devlinks(char *ap_log_id, const char *ap_id)
13650Sstevel@tonic-gate {
13660Sstevel@tonic-gate 	di_devlink_handle_t hdl;
13670Sstevel@tonic-gate 
13680Sstevel@tonic-gate 	DBG(1, ("check_devlinks: %s\n", ap_id));
13690Sstevel@tonic-gate 
13700Sstevel@tonic-gate 	hdl = di_devlink_init(NULL, 0);
13710Sstevel@tonic-gate 
13720Sstevel@tonic-gate 	if (strncmp("/devices/", ap_id, 9) == 0) {
13730Sstevel@tonic-gate 		/* ap_id is a valid minor_path with /devices prepended */
13740Sstevel@tonic-gate 		(void) di_devlink_walk(hdl, NULL, ap_id + 8, DI_PRIMARY_LINK,
13750Sstevel@tonic-gate 		    (void *)ap_log_id, found_devlink);
13760Sstevel@tonic-gate 	} else {
13770Sstevel@tonic-gate 		DBG(1, ("check_devlinks: invalid ap_id: %s\n", ap_id));
13780Sstevel@tonic-gate 		return (CFGA_ERROR);
13790Sstevel@tonic-gate 	}
13800Sstevel@tonic-gate 
13810Sstevel@tonic-gate 	(void) di_devlink_fini(&hdl);
13820Sstevel@tonic-gate 
13830Sstevel@tonic-gate 	if (ap_log_id[0] != '\0')
13840Sstevel@tonic-gate 		return (CFGA_OK);
13850Sstevel@tonic-gate 	else
13860Sstevel@tonic-gate 		return (CFGA_ERROR);
13870Sstevel@tonic-gate }
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate /*
13900Sstevel@tonic-gate  * most of this is needed to compensate for
13910Sstevel@tonic-gate  * differences between various platforms
13920Sstevel@tonic-gate  */
13930Sstevel@tonic-gate static cfga_err_t
13940Sstevel@tonic-gate fix_ap_name(char *ap_log_id, const char *ap_id, char *slot_name,
13950Sstevel@tonic-gate     char **errstring)
13960Sstevel@tonic-gate {
13970Sstevel@tonic-gate 	char *buf;
13980Sstevel@tonic-gate 	char *tmp;
13990Sstevel@tonic-gate 	char *ptr;
14000Sstevel@tonic-gate 
14010Sstevel@tonic-gate 	di_node_t ap_node;
14020Sstevel@tonic-gate 
14030Sstevel@tonic-gate 	ap_log_id[0] = '\0';
14040Sstevel@tonic-gate 
14050Sstevel@tonic-gate 	if (check_devlinks(ap_log_id, ap_id) == CFGA_OK)
14060Sstevel@tonic-gate 		return (CFGA_OK);
14070Sstevel@tonic-gate 
14080Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", ap_id));
14090Sstevel@tonic-gate 
14100Sstevel@tonic-gate 	if ((buf = malloc(strlen(ap_id) + 1)) == NULL) {
14110Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
14120Sstevel@tonic-gate 		return (CFGA_ERROR);
14130Sstevel@tonic-gate 	}
14140Sstevel@tonic-gate 	(void) strcpy(buf, ap_id);
14150Sstevel@tonic-gate 	tmp = buf + sizeof ("/devices") - 1;
14160Sstevel@tonic-gate 
14170Sstevel@tonic-gate 	ptr = strchr(tmp, ':');
14180Sstevel@tonic-gate 	ptr[0] = '\0';
14190Sstevel@tonic-gate 
14200Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", tmp));
14210Sstevel@tonic-gate 
14220Sstevel@tonic-gate 	ap_node = di_init(tmp, DINFOMINOR);
14230Sstevel@tonic-gate 	if (ap_node == DI_NODE_NIL) {
14240Sstevel@tonic-gate 		cfga_err(errstring, "di_init ", 0);
14250Sstevel@tonic-gate 		DBG(1, ("fix_ap_name: failed to snapshot node\n"));
14260Sstevel@tonic-gate 		return (CFGA_ERROR);
14270Sstevel@tonic-gate 	}
14280Sstevel@tonic-gate 
14290Sstevel@tonic-gate 	(void) snprintf(ap_log_id, strlen(ap_id) + 1, "%s%i:%s",
14300Sstevel@tonic-gate 	    di_driver_name(ap_node), di_instance(ap_node), slot_name);
14310Sstevel@tonic-gate 
14320Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", ap_log_id));
14330Sstevel@tonic-gate 
14340Sstevel@tonic-gate 	di_fini(ap_node);
14350Sstevel@tonic-gate 
14360Sstevel@tonic-gate 	free(buf);
14370Sstevel@tonic-gate 	return (CFGA_OK);
14380Sstevel@tonic-gate }
14390Sstevel@tonic-gate 
14400Sstevel@tonic-gate /*ARGSUSED*/
14410Sstevel@tonic-gate cfga_err_t
14420Sstevel@tonic-gate cfga_list_ext(const char *ap_id, cfga_list_data_t **cs,
14430Sstevel@tonic-gate     int *nlist, const char *options, const char *listopts, char **errstring,
14440Sstevel@tonic-gate     cfga_flags_t flags)
14450Sstevel@tonic-gate {
14460Sstevel@tonic-gate 	devctl_hdl_t		dcp;
14470Sstevel@tonic-gate 	struct hpc_control_data	iocdata;
14480Sstevel@tonic-gate 	devctl_ap_state_t	state;
14490Sstevel@tonic-gate 	hpc_board_type_t	boardtype;
14500Sstevel@tonic-gate 	hpc_card_info_t		cardinfo;
14510Sstevel@tonic-gate 	hpc_slot_info_t		slot_info;
14520Sstevel@tonic-gate 	struct	searcharg	slotname_arg;
14530Sstevel@tonic-gate 	int			fd;
14540Sstevel@tonic-gate 	int			rv = CFGA_OK;
14550Sstevel@tonic-gate 
14560Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
14570Sstevel@tonic-gate 		return (rv);
14580Sstevel@tonic-gate 	}
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate 	if (errstring != NULL)
14610Sstevel@tonic-gate 		*errstring = NULL;
14620Sstevel@tonic-gate 
14630Sstevel@tonic-gate 	(void) memset(&slot_info, 0, sizeof (hpc_slot_info_t));
14640Sstevel@tonic-gate 
14650Sstevel@tonic-gate 	DBG(1, ("cfga_list_ext:(%s)\n", ap_id));
14660Sstevel@tonic-gate 
14670Sstevel@tonic-gate 	if (cs == NULL || nlist == NULL) {
14680Sstevel@tonic-gate 		rv = CFGA_ERROR;
14690Sstevel@tonic-gate 		return (rv);
14700Sstevel@tonic-gate 	}
14710Sstevel@tonic-gate 
14720Sstevel@tonic-gate 	*nlist = 1;
14730Sstevel@tonic-gate 
14740Sstevel@tonic-gate 	if ((*cs = malloc(sizeof (cfga_list_data_t))) == NULL) {
14750Sstevel@tonic-gate 		cfga_err(errstring, "malloc ", 0);
14760Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
14770Sstevel@tonic-gate 		rv = CFGA_ERROR;
14780Sstevel@tonic-gate 		return (rv);
14790Sstevel@tonic-gate 	}
14800Sstevel@tonic-gate 
14810Sstevel@tonic-gate 	if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
14820Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, 0);
14830Sstevel@tonic-gate 		DBG(2, ("cfga_list_ext::(devctl_ap_acquire())\n"));
14840Sstevel@tonic-gate 		rv = CFGA_ERROR;
14850Sstevel@tonic-gate 		return (rv);
14860Sstevel@tonic-gate 	}
14870Sstevel@tonic-gate 
14880Sstevel@tonic-gate 	if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
14890Sstevel@tonic-gate 		cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
14900Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
14910Sstevel@tonic-gate 		DBG(2, ("cfga_list_ext::(devctl_ap_getstate())\n"));
14920Sstevel@tonic-gate 		rv = CFGA_ERROR;
14930Sstevel@tonic-gate 		return (rv);
14940Sstevel@tonic-gate 	}
14950Sstevel@tonic-gate 
14960Sstevel@tonic-gate 	switch (state.ap_rstate) {
14970Sstevel@tonic-gate 		case AP_RSTATE_EMPTY:
14980Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_EMPTY;
14990Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_EMPTY\n"));
15000Sstevel@tonic-gate 			break;
15010Sstevel@tonic-gate 		case AP_RSTATE_DISCONNECTED:
15020Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_DISCONNECTED;
15030Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_DISCONNECTED\n"));
15040Sstevel@tonic-gate 			break;
15050Sstevel@tonic-gate 		case AP_RSTATE_CONNECTED:
15060Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_CONNECTED;
15070Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_CONNECTED\n"));
15080Sstevel@tonic-gate 			break;
15090Sstevel@tonic-gate 	default:
15100Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
15110Sstevel@tonic-gate 		rv = CFGA_ERROR;
15120Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15130Sstevel@tonic-gate 		return (rv);
15140Sstevel@tonic-gate 	}
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate 	switch (state.ap_ostate) {
15170Sstevel@tonic-gate 		case AP_OSTATE_CONFIGURED:
15180Sstevel@tonic-gate 			(*cs)->ap_o_state = CFGA_STAT_CONFIGURED;
15190Sstevel@tonic-gate 			DBG(2, ("ap_ostate = CFGA_STAT_CONFIGURED\n"));
15200Sstevel@tonic-gate 			break;
15210Sstevel@tonic-gate 		case AP_OSTATE_UNCONFIGURED:
15220Sstevel@tonic-gate 			(*cs)->ap_o_state = CFGA_STAT_UNCONFIGURED;
15230Sstevel@tonic-gate 			DBG(2, ("ap_ostate = CFGA_STAT_UNCONFIGURED\n"));
15240Sstevel@tonic-gate 			break;
15250Sstevel@tonic-gate 	default:
15260Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
15270Sstevel@tonic-gate 		rv = CFGA_ERROR;
15280Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15290Sstevel@tonic-gate 		return (rv);
15300Sstevel@tonic-gate 	}
15310Sstevel@tonic-gate 
15320Sstevel@tonic-gate 	switch (state.ap_condition) {
15330Sstevel@tonic-gate 		case AP_COND_OK:
15340Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_OK;
15350Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_OK\n"));
15360Sstevel@tonic-gate 			break;
15370Sstevel@tonic-gate 		case AP_COND_FAILING:
15380Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_FAILING;
15390Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_FAILING\n"));
15400Sstevel@tonic-gate 			break;
15410Sstevel@tonic-gate 		case AP_COND_FAILED:
15420Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_FAILED;
15430Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_FAILED\n"));
15440Sstevel@tonic-gate 			break;
15450Sstevel@tonic-gate 		case AP_COND_UNUSABLE:
15460Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_UNUSABLE;
15470Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_UNUSABLE\n"));
15480Sstevel@tonic-gate 			break;
15490Sstevel@tonic-gate 		case AP_COND_UNKNOWN:
15500Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_UNKNOWN;
15510Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_UNKNOW\n"));
15520Sstevel@tonic-gate 			break;
15530Sstevel@tonic-gate 	default:
15540Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
15550Sstevel@tonic-gate 		rv = CFGA_ERROR;
15560Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15570Sstevel@tonic-gate 		return (rv);
15580Sstevel@tonic-gate 	}
15590Sstevel@tonic-gate 	(*cs)->ap_busy = (int)state.ap_in_transition;
15600Sstevel@tonic-gate 
15610Sstevel@tonic-gate 	devctl_release((devctl_hdl_t)dcp);
15620Sstevel@tonic-gate 
15630Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
15640Sstevel@tonic-gate 		cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
15650Sstevel@tonic-gate 		(*cs)->ap_status_time = 0;
15660Sstevel@tonic-gate 		boardtype = HPC_BOARD_UNKNOWN;
15670Sstevel@tonic-gate 		cardinfo.base_class = PCI_CLASS_NONE;
15680Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
15690Sstevel@tonic-gate 		DBG(2, ("open on %s failed\n", ap_id));
15700Sstevel@tonic-gate 		goto cont;
15710Sstevel@tonic-gate 	}
15720Sstevel@tonic-gate 	DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
15730Sstevel@tonic-gate 
15740Sstevel@tonic-gate 	(*cs)->ap_status_time = state.ap_last_change;
15750Sstevel@tonic-gate 
15760Sstevel@tonic-gate 	/* need board type and a way to get to hpc_slot_info */
15770Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_BOARD_TYPE,
15780Sstevel@tonic-gate 	    (void *)&boardtype);
15790Sstevel@tonic-gate 
15800Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
15810Sstevel@tonic-gate 		boardtype = HPC_BOARD_UNKNOWN;
15820Sstevel@tonic-gate 	}
15830Sstevel@tonic-gate 	DBG(1, ("ioctl boardtype\n"));
15840Sstevel@tonic-gate 
15850Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
15860Sstevel@tonic-gate 	    (void *)&slot_info);
15870Sstevel@tonic-gate 
15880Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
15890Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
15900Sstevel@tonic-gate 		DBG(1, ("ioctl failed slotinfo: %s\n",
15910Sstevel@tonic-gate 		    slot_info.pci_slot_name));
15920Sstevel@tonic-gate 	} else {
15930Sstevel@tonic-gate 
15940Sstevel@tonic-gate 		/*
15950Sstevel@tonic-gate 		 * the driver will report back things like hpc0_slot0
15960Sstevel@tonic-gate 		 * this needs to be changed to things like pci1:hpc0_slot0
15970Sstevel@tonic-gate 		 */
15980Sstevel@tonic-gate 		rv = fix_ap_name((*cs)->ap_log_id,
15990Sstevel@tonic-gate 		    ap_id, slot_info.pci_slot_name, errstring);
16000Sstevel@tonic-gate 		DBG(1, ("ioctl slotinfo: %s\n", (*cs)->ap_log_id));
16010Sstevel@tonic-gate 	}
16020Sstevel@tonic-gate 
16030Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_CARD_INFO,
16040Sstevel@tonic-gate 	    (void *)&cardinfo);
16050Sstevel@tonic-gate 
16060Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
16070Sstevel@tonic-gate 		DBG(1, ("ioctl failed\n"));
16080Sstevel@tonic-gate 		cardinfo.base_class = PCI_CLASS_NONE;
16090Sstevel@tonic-gate 	}
16100Sstevel@tonic-gate 
16110Sstevel@tonic-gate 	DBG(1, ("ioctl cardinfo: %d\n", cardinfo.base_class));
16120Sstevel@tonic-gate 	DBG(1, ("ioctl subclass: %d\n", cardinfo.sub_class));
16130Sstevel@tonic-gate 	DBG(1, ("ioctl headertype: %d\n", cardinfo.header_type));
16140Sstevel@tonic-gate 
16150Sstevel@tonic-gate 	(void) close(fd);
16160Sstevel@tonic-gate 
16170Sstevel@tonic-gate cont:
16180Sstevel@tonic-gate 	(void) strcpy((*cs)->ap_phys_id, ap_id);    /* physical path of AP */
16190Sstevel@tonic-gate 	if ((*cs)->ap_log_id[0] == '\0')
16200Sstevel@tonic-gate 		(void) strcpy((*cs)->ap_log_id, slot_info.pci_slot_name);
16210Sstevel@tonic-gate 
16220Sstevel@tonic-gate 	/* slot_names of bus node  */
16230Sstevel@tonic-gate 	if (find_physical_slot_names(ap_id, &slotname_arg) != -1)
16240Sstevel@tonic-gate 		(void) strcpy((*cs)->ap_info,
16250Sstevel@tonic-gate 		    slotname_arg.slotnames[slotname_arg.minor]);
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate 	(void) memset((*cs)->ap_type, 0, CFGA_TYPE_LEN);
16280Sstevel@tonic-gate 	/* class_code/subclass/boardtype */
16290Sstevel@tonic-gate 	get_type(boardtype, cardinfo, (*cs)->ap_type);
16300Sstevel@tonic-gate 
16310Sstevel@tonic-gate 	DBG(1, ("cfga_list_ext return success\n"));
16320Sstevel@tonic-gate 	rv = CFGA_OK;
16330Sstevel@tonic-gate 
16340Sstevel@tonic-gate 	return (rv);
16350Sstevel@tonic-gate }
16360Sstevel@tonic-gate 
16370Sstevel@tonic-gate /*
16380Sstevel@tonic-gate  * This routine prints a single line of help message
16390Sstevel@tonic-gate  */
16400Sstevel@tonic-gate static void
16410Sstevel@tonic-gate cfga_msg(struct cfga_msg *msgp, const char *str)
16420Sstevel@tonic-gate {
16430Sstevel@tonic-gate 	DBG(2, ("<%s>", str));
16440Sstevel@tonic-gate 
16450Sstevel@tonic-gate 	if (msgp == NULL || msgp->message_routine == NULL)
16460Sstevel@tonic-gate 		return;
16470Sstevel@tonic-gate 
16480Sstevel@tonic-gate 	(*msgp->message_routine)(msgp->appdata_ptr, str);
16490Sstevel@tonic-gate 	(*msgp->message_routine)(msgp->appdata_ptr, "\n");
16500Sstevel@tonic-gate }
16510Sstevel@tonic-gate 
16520Sstevel@tonic-gate static cfga_err_t
16530Sstevel@tonic-gate check_options(const char *options)
16540Sstevel@tonic-gate {
16550Sstevel@tonic-gate 	struct cfga_msg *msgp = NULL;
16560Sstevel@tonic-gate 
16570Sstevel@tonic-gate 	if (options) {
16580Sstevel@tonic-gate 		cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
16590Sstevel@tonic-gate 		cfga_msg(msgp, options);
16600Sstevel@tonic-gate 		return (CFGA_INVAL);
16610Sstevel@tonic-gate 	}
16620Sstevel@tonic-gate 	return (CFGA_OK);
16630Sstevel@tonic-gate }
16640Sstevel@tonic-gate 
16650Sstevel@tonic-gate /*ARGSUSED*/
16660Sstevel@tonic-gate cfga_err_t
16670Sstevel@tonic-gate cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
16680Sstevel@tonic-gate {
16690Sstevel@tonic-gate 	if (options) {
16700Sstevel@tonic-gate 		cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
16710Sstevel@tonic-gate 		cfga_msg(msgp, options);
16720Sstevel@tonic-gate 	}
16730Sstevel@tonic-gate 	DBG(1, ("cfga_help\n"));
16740Sstevel@tonic-gate 
16750Sstevel@tonic-gate 	cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_HEADER]));
16760Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_CONFIG]);
16770Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_ENABLE_SLOT]);
16780Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_DISABLE_SLOT]);
16790Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_ENABLE_AUTOCONF]);
16800Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_DISABLE_AUTOCONF]);
16810Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_LED_CNTRL]);
16820Sstevel@tonic-gate 	return (CFGA_OK);
16830Sstevel@tonic-gate }
16840Sstevel@tonic-gate 
16850Sstevel@tonic-gate /*
16860Sstevel@tonic-gate  * cfga_err() accepts a variable number of message IDs and constructs
16870Sstevel@tonic-gate  * a corresponding error string which is returned via the errstring argument.
16880Sstevel@tonic-gate  * cfga_err() calls gettext() to internationalize proper messages.
16890Sstevel@tonic-gate  */
16900Sstevel@tonic-gate static void
16910Sstevel@tonic-gate cfga_err(char **errstring, ...)
16920Sstevel@tonic-gate {
16930Sstevel@tonic-gate 	int a;
16940Sstevel@tonic-gate 	int i;
16950Sstevel@tonic-gate 	int n;
16960Sstevel@tonic-gate 	int len;
16970Sstevel@tonic-gate 	int flen;
16980Sstevel@tonic-gate 	char *p;
16990Sstevel@tonic-gate 	char *q;
17000Sstevel@tonic-gate 	char *s[32];
17010Sstevel@tonic-gate 	char *failed;
17020Sstevel@tonic-gate 	va_list ap;
17030Sstevel@tonic-gate 
17040Sstevel@tonic-gate 	/*
17050Sstevel@tonic-gate 	 * If errstring is null it means user in not interested in getting
17060Sstevel@tonic-gate 	 * error status. So we don't do all the work
17070Sstevel@tonic-gate 	 */
17080Sstevel@tonic-gate 	if (errstring == NULL) {
17090Sstevel@tonic-gate 		return;
17100Sstevel@tonic-gate 	}
17110Sstevel@tonic-gate 	va_start(ap, errstring);
17120Sstevel@tonic-gate 
17130Sstevel@tonic-gate 	failed = dgettext(TEXT_DOMAIN, cfga_strs[FAILED]);
17140Sstevel@tonic-gate 	flen = strlen(failed);
17150Sstevel@tonic-gate 
17160Sstevel@tonic-gate 	for (n = len = 0; (a = va_arg(ap, int)) != 0; n++) {
17170Sstevel@tonic-gate 		switch (a) {
17180Sstevel@tonic-gate 		case CMD_GETSTAT:
17190Sstevel@tonic-gate 		case CMD_LIST:
17200Sstevel@tonic-gate 		case CMD_SLOT_CONNECT:
17210Sstevel@tonic-gate 		case CMD_SLOT_DISCONNECT:
17220Sstevel@tonic-gate 		case CMD_SLOT_CONFIGURE:
17230Sstevel@tonic-gate 		case CMD_SLOT_UNCONFIGURE:
17240Sstevel@tonic-gate 			p =  cfga_errstrs(a);
17250Sstevel@tonic-gate 			len += (strlen(p) + flen);
17260Sstevel@tonic-gate 			s[n] = p;
17270Sstevel@tonic-gate 			s[++n] = cfga_strs[FAILED];
17280Sstevel@tonic-gate 
17290Sstevel@tonic-gate 			DBG(2, ("<%s>", p));
17300Sstevel@tonic-gate 			DBG(2, (cfga_strs[FAILED]));
17310Sstevel@tonic-gate 			break;
17320Sstevel@tonic-gate 
17330Sstevel@tonic-gate 		case ERR_CMD_INVAL:
17340Sstevel@tonic-gate 		case ERR_AP_INVAL:
17350Sstevel@tonic-gate 		case ERR_OPT_INVAL:
17360Sstevel@tonic-gate 		case ERR_AP_ERR:
17370Sstevel@tonic-gate 			switch (a) {
17380Sstevel@tonic-gate 			case ERR_CMD_INVAL:
17390Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
17400Sstevel@tonic-gate 				    cfga_errstrs[ERR_CMD_INVAL]);
17410Sstevel@tonic-gate 				break;
17420Sstevel@tonic-gate 			case ERR_AP_INVAL:
17430Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
17440Sstevel@tonic-gate 				    cfga_errstrs[ERR_AP_INVAL]);
17450Sstevel@tonic-gate 				break;
17460Sstevel@tonic-gate 			case ERR_OPT_INVAL:
17470Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
17480Sstevel@tonic-gate 				    cfga_errstrs[ERR_OPT_INVAL]);
17490Sstevel@tonic-gate 				break;
17500Sstevel@tonic-gate 			case ERR_AP_ERR:
17510Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
17520Sstevel@tonic-gate 				    cfga_errstrs[ERR_AP_ERR]);
17530Sstevel@tonic-gate 				break;
17540Sstevel@tonic-gate 			}
17550Sstevel@tonic-gate 
17560Sstevel@tonic-gate 			if ((q = va_arg(ap, char *)) != NULL) {
17570Sstevel@tonic-gate 				len += (strlen(p) + strlen(q));
17580Sstevel@tonic-gate 				s[n] = p;
17590Sstevel@tonic-gate 				s[++n] = q;
17600Sstevel@tonic-gate 				DBG(2, ("<%s>", p));
17610Sstevel@tonic-gate 				DBG(2, ("<%s>", q));
17620Sstevel@tonic-gate 				break;
17630Sstevel@tonic-gate 			} else {
17640Sstevel@tonic-gate 				len += strlen(p);
17650Sstevel@tonic-gate 				s[n] = p;
17660Sstevel@tonic-gate 
17670Sstevel@tonic-gate 			}
17680Sstevel@tonic-gate 			DBG(2, ("<%s>", p));
17690Sstevel@tonic-gate 			break;
17700Sstevel@tonic-gate 
17710Sstevel@tonic-gate 		default:
17720Sstevel@tonic-gate 			n--;
17730Sstevel@tonic-gate 			break;
17740Sstevel@tonic-gate 		}
17750Sstevel@tonic-gate 	}
17760Sstevel@tonic-gate 
17770Sstevel@tonic-gate 	DBG(2, ("\n"));
17780Sstevel@tonic-gate 	va_end(ap);
17790Sstevel@tonic-gate 
17800Sstevel@tonic-gate 	if ((p = calloc(len + 1, 1)) == NULL)
17810Sstevel@tonic-gate 		return;
17820Sstevel@tonic-gate 
17830Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
17840Sstevel@tonic-gate 		(void) strlcat(p, s[i], len + 1);
17850Sstevel@tonic-gate 		DBG(2, ("i:%d, %s\n", i, s[i]));
17860Sstevel@tonic-gate 	}
17870Sstevel@tonic-gate 
17880Sstevel@tonic-gate 	*errstring = p;
17890Sstevel@tonic-gate #ifdef	DEBUG
17900Sstevel@tonic-gate 	printf("%s\n", *errstring);
17910Sstevel@tonic-gate 	free(*errstring);
17920Sstevel@tonic-gate #endif
17930Sstevel@tonic-gate }
17940Sstevel@tonic-gate 
17950Sstevel@tonic-gate /*
17960Sstevel@tonic-gate  * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm
17970Sstevel@tonic-gate  */
1798