17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
548c888ecSkd  * Common Development and Distribution License (the "License").
648c888ecSkd  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2109f67678Sanish 
227c478bd9Sstevel@tonic-gate /*
2348c888ecSkd  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  *	Plugin Library for PCI Hot-Plug Controller
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <stddef.h>
327c478bd9Sstevel@tonic-gate #include <locale.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <fcntl.h>
387c478bd9Sstevel@tonic-gate #include <unistd.h>
397c478bd9Sstevel@tonic-gate #include <errno.h>
407c478bd9Sstevel@tonic-gate #include <locale.h>
417c478bd9Sstevel@tonic-gate #include <langinfo.h>
427c478bd9Sstevel@tonic-gate #include <time.h>
437c478bd9Sstevel@tonic-gate #include <sys/param.h>
447c478bd9Sstevel@tonic-gate #include <stdarg.h>
457c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
467c478bd9Sstevel@tonic-gate #include <libdevice.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	CFGA_PLUGIN_LIB
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include <config_admin.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <sys/types.h>
537c478bd9Sstevel@tonic-gate #include <sys/stat.h>
547c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
557c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
567c478bd9Sstevel@tonic-gate #include <sys/devctl.h>
577c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
587c478bd9Sstevel@tonic-gate #include <sys/hotplug/hpctrl.h>
597c478bd9Sstevel@tonic-gate #include <sys/pci.h>
607c478bd9Sstevel@tonic-gate #include <libintl.h>
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #include <dirent.h>
637c478bd9Sstevel@tonic-gate #include <limits.h>
647c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
657c478bd9Sstevel@tonic-gate #include <librcm.h>
6609f67678Sanish #include "../../../../common/pci/pci_strings.h"
6709f67678Sanish 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Set the version number
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate int cfga_version = CFGA_HSL_V2;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #ifdef	DEBUG
747c478bd9Sstevel@tonic-gate #define	PCIHP_DBG	1
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
787c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
797c478bd9Sstevel@tonic-gate #endif
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  *	DEBUGING LEVEL
837c478bd9Sstevel@tonic-gate  *
84014ec826SToomas Soome  *	External routines:  1 - 2
857c478bd9Sstevel@tonic-gate  *	Internal routines:  3 - 4
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate #ifdef	PCIHP_DBG
887c478bd9Sstevel@tonic-gate int	pcihp_debug = 1;
897c478bd9Sstevel@tonic-gate #define	DBG(level, args) \
907c478bd9Sstevel@tonic-gate 	{ if (pcihp_debug >= (level)) printf args; }
917c478bd9Sstevel@tonic-gate #define	DBG_F(level, args) \
927c478bd9Sstevel@tonic-gate 	{ if (pcihp_debug >= (level)) fprintf args; }
937c478bd9Sstevel@tonic-gate #else
947c478bd9Sstevel@tonic-gate #define	DBG(level, args)	/* nothing */
957c478bd9Sstevel@tonic-gate #define	DBG_F(level, args)	/* nothing */
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	CMD_ACQUIRE		0
997c478bd9Sstevel@tonic-gate #define	CMD_GETSTAT		1
1007c478bd9Sstevel@tonic-gate #define	CMD_LIST		2
1017c478bd9Sstevel@tonic-gate #define	CMD_SLOT_CONNECT	3
1027c478bd9Sstevel@tonic-gate #define	CMD_SLOT_DISCONNECT	4
1037c478bd9Sstevel@tonic-gate #define	CMD_SLOT_CONFIGURE	5
1047c478bd9Sstevel@tonic-gate #define	CMD_SLOT_UNCONFIGURE	6
1057c478bd9Sstevel@tonic-gate #define	CMD_SLOT_INSERT		7
1067c478bd9Sstevel@tonic-gate #define	CMD_SLOT_REMOVE		8
1077c478bd9Sstevel@tonic-gate #define	CMD_OPEN		9
1087c478bd9Sstevel@tonic-gate #define	CMD_FSTAT		10
1097c478bd9Sstevel@tonic-gate #define	ERR_CMD_INVAL		11
1107c478bd9Sstevel@tonic-gate #define	ERR_AP_INVAL		12
1117c478bd9Sstevel@tonic-gate #define	ERR_AP_ERR		13
1127c478bd9Sstevel@tonic-gate #define	ERR_OPT_INVAL		14
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate static char *
1157c478bd9Sstevel@tonic-gate cfga_errstrs[] = {
1167c478bd9Sstevel@tonic-gate 	/* n */ "acquire ",
1177c478bd9Sstevel@tonic-gate 	/* n */ "get-status ",
1187c478bd9Sstevel@tonic-gate 	/* n */ "list ",
1197c478bd9Sstevel@tonic-gate 	/* n */ "connect ",
1207c478bd9Sstevel@tonic-gate 	/* n */ "disconnect ",
1217c478bd9Sstevel@tonic-gate 	/* n */ "configure ",
1227c478bd9Sstevel@tonic-gate 	/* n */ "unconfigure ",
1237c478bd9Sstevel@tonic-gate 	/* n */ "insert ",
1247c478bd9Sstevel@tonic-gate 	/* n */ "remove ",
1257c478bd9Sstevel@tonic-gate 	/* n */ "open ",
1267c478bd9Sstevel@tonic-gate 	/* n */ "fstat ",
1277c478bd9Sstevel@tonic-gate 	/* y */ "invalid command ",
1287c478bd9Sstevel@tonic-gate 	/* y */ "invalid attachment point ",
1297c478bd9Sstevel@tonic-gate 	/* y */ "invalid transition ",
1307c478bd9Sstevel@tonic-gate 	/* y */ "invalid option ",
1317c478bd9Sstevel@tonic-gate 		NULL
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #define	HELP_HEADER		1
1357c478bd9Sstevel@tonic-gate #define	HELP_CONFIG		2
1367c478bd9Sstevel@tonic-gate #define	HELP_ENABLE_SLOT	3
1377c478bd9Sstevel@tonic-gate #define	HELP_DISABLE_SLOT	4
1387c478bd9Sstevel@tonic-gate #define	HELP_ENABLE_AUTOCONF	5
1397c478bd9Sstevel@tonic-gate #define	HELP_DISABLE_AUTOCONF	6
1407c478bd9Sstevel@tonic-gate #define	HELP_LED_CNTRL		7
1417c478bd9Sstevel@tonic-gate #define	HELP_UNKNOWN		8
1427c478bd9Sstevel@tonic-gate #define	SUCCESS			9
1437c478bd9Sstevel@tonic-gate #define	FAILED			10
1447c478bd9Sstevel@tonic-gate #define	UNKNOWN			11
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	MAXLINE			256
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* for type string assembly in get_type() */
1497c478bd9Sstevel@tonic-gate #define	TPCT(s)	(void) strlcat(buf, (s), CFGA_TYPE_LEN)
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate extern int errno;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate static void cfga_err(char **errstring, ...);
1547c478bd9Sstevel@tonic-gate static cfga_err_t fix_ap_name(char *ap_log_id, const char *ap_id,
1557c478bd9Sstevel@tonic-gate     char *slot_name, char **errstring);
1567c478bd9Sstevel@tonic-gate static void build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
1577c478bd9Sstevel@tonic-gate     void *retdata);
1587c478bd9Sstevel@tonic-gate static cfga_err_t check_options(const char *options);
1597c478bd9Sstevel@tonic-gate static void cfga_msg(struct cfga_msg *msgp, const char *str);
1603c4226f9Spjha static char *findlink(char *ap_phys_id);
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate static char *
1637c478bd9Sstevel@tonic-gate cfga_strs[] = {
1647c478bd9Sstevel@tonic-gate NULL,
1657c478bd9Sstevel@tonic-gate "\nPCI hotplug specific commands:",
1667c478bd9Sstevel@tonic-gate "\t-c [connect|disconnect|configure|unconfigure|insert|remove] "
1677c478bd9Sstevel@tonic-gate "ap_id [ap_id...]",
1687c478bd9Sstevel@tonic-gate "\t-x enable_slot  ap_id [ap_id...]",
1697c478bd9Sstevel@tonic-gate "\t-x disable_slot ap_id [ap_id...]",
1707c478bd9Sstevel@tonic-gate "\t-x enable_autoconfig  ap_id [ap_id...]",
1717c478bd9Sstevel@tonic-gate "\t-x disable_autoconfig ap_id [ap_id...]",
1727c478bd9Sstevel@tonic-gate "\t-x led[=[fault|power|active|attn],mode=[on|off|blink]] ap_id [ap_id...]",
1737c478bd9Sstevel@tonic-gate "\tunknown command or option: ",
1747c478bd9Sstevel@tonic-gate "success   ",
1757c478bd9Sstevel@tonic-gate "failed   ",
1767c478bd9Sstevel@tonic-gate "unknown",
1777c478bd9Sstevel@tonic-gate NULL
1787c478bd9Sstevel@tonic-gate };
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #define	MAX_FORMAT 80
1817c478bd9Sstevel@tonic-gate 
18209f67678Sanish #define	ENABLE_SLOT	0
18309f67678Sanish #define	DISABLE_SLOT	1
18409f67678Sanish #define	ENABLE_AUTOCNF	2
18509f67678Sanish #define	DISABLE_AUTOCNF	3
18609f67678Sanish #define	LED		4
18709f67678Sanish #define	MODE		5
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Board Type
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate static char *
1937c478bd9Sstevel@tonic-gate board_strs[] = {
1947c478bd9Sstevel@tonic-gate 	/* n */ "???",	/* HPC_BOARD_UNKNOWN */
1957c478bd9Sstevel@tonic-gate 	/* n */ "hp",	/* HPC_BOARD_PCI_HOTPLUG */
1967c478bd9Sstevel@tonic-gate 	/* n */ "nhs",	/* HPC_BOARD_CPCI_NON_HS */
1977c478bd9Sstevel@tonic-gate 	/* n */ "bhs",  /* HPC_BOARD_CPCI_BASIC_HS */
1987c478bd9Sstevel@tonic-gate 	/* n */ "fhs",	/* HPC_BOARD_CPCI_FULL_HS */
1997c478bd9Sstevel@tonic-gate 	/* n */ "hs",	/* HPC_BOARD_CPCI_HS */
2007c478bd9Sstevel@tonic-gate 	/* n */ NULL
2017c478bd9Sstevel@tonic-gate };
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * HW functions
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate static char *
2077c478bd9Sstevel@tonic-gate func_strs[] = {
20809f67678Sanish 	/* n */ "enable_slot",
2097c478bd9Sstevel@tonic-gate 	/* n */ "disable_slot",
2107c478bd9Sstevel@tonic-gate 	/* n */ "enable_autoconfig",
2117c478bd9Sstevel@tonic-gate 	/* n */ "disable_autoconfig",
2127c478bd9Sstevel@tonic-gate 	/* n */ "led",
2137c478bd9Sstevel@tonic-gate 	/* n */ "mode",
2147c478bd9Sstevel@tonic-gate 	/* n */ NULL
2157c478bd9Sstevel@tonic-gate };
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * LED strings
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate static char *
2217c478bd9Sstevel@tonic-gate led_strs[] = {
2227c478bd9Sstevel@tonic-gate 	/* n */ "fault",	/* HPC_FAULT_LED */
2237c478bd9Sstevel@tonic-gate 	/* n */ "power",	/* HPC_POWER_LED */
2247c478bd9Sstevel@tonic-gate 	/* n */ "attn",		/* HPC_ATTN_LED */
2257c478bd9Sstevel@tonic-gate 	/* n */ "active",	/* HPC_ACTIVE_LED */
2267c478bd9Sstevel@tonic-gate 	/* n */ NULL
2277c478bd9Sstevel@tonic-gate };
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #define	FAULT	0
2307c478bd9Sstevel@tonic-gate #define	POWER	1
2317c478bd9Sstevel@tonic-gate #define	ATTN	2
2327c478bd9Sstevel@tonic-gate #define	ACTIVE	3
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate static char *
2357c478bd9Sstevel@tonic-gate mode_strs[] = {
2367c478bd9Sstevel@tonic-gate 	/* n */ "off",		/* HPC_LED_OFF */
2377c478bd9Sstevel@tonic-gate 	/* n */ "on",		/* HPC_LED_ON */
2387c478bd9Sstevel@tonic-gate 	/* n */ "blink",	/* HPC_LED_BLINK */
2397c478bd9Sstevel@tonic-gate 	/* n */	NULL
2407c478bd9Sstevel@tonic-gate };
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate #define	OFF	0
2437c478bd9Sstevel@tonic-gate #define	ON	1
2447c478bd9Sstevel@tonic-gate #define	BLINK	2
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate #define	cfga_errstrs(i)		cfga_errstrs[(i)]
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate #define	cfga_eid(a, b)		(((a) << 8) + (b))
2497c478bd9Sstevel@tonic-gate #define	MAXDEVS			32
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate typedef enum {
2527c478bd9Sstevel@tonic-gate 	SOLARIS_SLT_NAME,
2537c478bd9Sstevel@tonic-gate 	PROM_SLT_NAME
2547c478bd9Sstevel@tonic-gate } slt_name_src_t;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate struct searcharg {
2577c478bd9Sstevel@tonic-gate 	char	*devpath;
2587c478bd9Sstevel@tonic-gate 	char	slotnames[MAXDEVS][MAXNAMELEN];
2597c478bd9Sstevel@tonic-gate 	int	minor;
2607c478bd9Sstevel@tonic-gate 	di_prom_handle_t	promp;
2617c478bd9Sstevel@tonic-gate 	slt_name_src_t	slt_name_src;
2627c478bd9Sstevel@tonic-gate };
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate static void *private_check;
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate static int
get_occupants(const char * ap_id,hpc_occupant_info_t * occupant)2677c478bd9Sstevel@tonic-gate get_occupants(const char *ap_id, hpc_occupant_info_t *occupant)
2687c478bd9Sstevel@tonic-gate {
2697c478bd9Sstevel@tonic-gate 	int rv;
2707c478bd9Sstevel@tonic-gate 	int fd;
2717c478bd9Sstevel@tonic-gate 	di_node_t ap_node;
2727c478bd9Sstevel@tonic-gate 	char *prop_data;
2737c478bd9Sstevel@tonic-gate 	char *tmp;
2747c478bd9Sstevel@tonic-gate 	char *ptr;
2757c478bd9Sstevel@tonic-gate 	struct stat statbuf;
2767c478bd9Sstevel@tonic-gate 	dev_t devt;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
2797c478bd9Sstevel@tonic-gate 		DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
2807c478bd9Sstevel@tonic-gate 		DBG_F(2, (stderr, "open on %s failed\n", ap_id));
2817c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
2827c478bd9Sstevel@tonic-gate 	}
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	if (fstat(fd, &statbuf) == -1) {
2857c478bd9Sstevel@tonic-gate 		DBG(1, ("stat failed: %i\n", errno));
2867c478bd9Sstevel@tonic-gate 		(void) close(fd);
2877c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate 	(void) close(fd);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	devt = statbuf.st_rdev;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	tmp = (char *)(ap_id + sizeof ("/devices") - 1);
2947c478bd9Sstevel@tonic-gate 	if ((ptr = strrchr(tmp, ':')) != NULL)
2957c478bd9Sstevel@tonic-gate 		*ptr = '\0';
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	ap_node = di_init(tmp, DINFOPROP | DINFOMINOR);
2987c478bd9Sstevel@tonic-gate 	if (ap_node == DI_NODE_NIL) {
2997c478bd9Sstevel@tonic-gate 		DBG(1, ("dead %i\n", errno));
3007c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
3017c478bd9Sstevel@tonic-gate 	}
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate #ifdef	PCIHP_DBG
3047c478bd9Sstevel@tonic-gate 	ptr = di_devfs_path(ap_node);
3057c478bd9Sstevel@tonic-gate 	DBG(1, ("get_occupants: %s\n", ptr));
3067c478bd9Sstevel@tonic-gate 	di_devfs_path_free(ptr);
3077c478bd9Sstevel@tonic-gate #endif
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	if ((rv = di_prop_lookup_strings(devt, ap_node, "pci-occupant",
3107c478bd9Sstevel@tonic-gate 	    &prop_data)) == -1) {
3117c478bd9Sstevel@tonic-gate 		DBG(1, ("get_occupants: prop_lookup failed: %i\n", errno));
3127c478bd9Sstevel@tonic-gate 		di_fini(ap_node);
3137c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if (prop_data && (strcmp(prop_data, "") == 0)) {
3177c478bd9Sstevel@tonic-gate 		di_fini(ap_node);
3187c478bd9Sstevel@tonic-gate 		occupant->i = 0;
3197c478bd9Sstevel@tonic-gate 		occupant->id[0] = NULL;
3207c478bd9Sstevel@tonic-gate 		return (CFGA_OK);
3217c478bd9Sstevel@tonic-gate 	}
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	DBG(1, ("get_occupants: %i devices found\n", rv));
3247c478bd9Sstevel@tonic-gate 	for (occupant->i = 0; occupant->i < rv; occupant->i++) {
3257c478bd9Sstevel@tonic-gate 		if (occupant->i >= (HPC_MAX_OCCUPANTS - 1)) {
3267c478bd9Sstevel@tonic-gate 			occupant->i--;
3277c478bd9Sstevel@tonic-gate 			break;
3287c478bd9Sstevel@tonic-gate 		}
3297c478bd9Sstevel@tonic-gate 		occupant->id[occupant->i] = (char *)malloc(
3302411ecfcSToomas Soome 		    strlen(prop_data) + sizeof ("/devices"));
3317c478bd9Sstevel@tonic-gate 		(void) snprintf(occupant->id[occupant->i], strlen(prop_data) +
3327c478bd9Sstevel@tonic-gate 		    sizeof ("/devices"), "/devices%s", prop_data);
3337c478bd9Sstevel@tonic-gate 		DBG(1, ("%s\n", occupant->id[occupant->i]));
3347c478bd9Sstevel@tonic-gate 		prop_data += strlen(prop_data) + 1;
3357c478bd9Sstevel@tonic-gate 	}
3367c478bd9Sstevel@tonic-gate 	di_fini(ap_node);
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	occupant->id[occupant->i] = NULL;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * let rcm know that the device has indeed been removed and clean
3457c478bd9Sstevel@tonic-gate  * up rcm data
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate static void
confirm_rcm(hpc_occupant_info_t * occupant,rcm_handle_t * rhandle)3487c478bd9Sstevel@tonic-gate confirm_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
3497c478bd9Sstevel@tonic-gate {
3507c478bd9Sstevel@tonic-gate 	DBG(1, ("confirm_rcm\n"));
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	if (occupant->i == 0) /* nothing was found to ask rcm about */
3537c478bd9Sstevel@tonic-gate 		return;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	(void) rcm_notify_remove_list(rhandle, occupant->id, 0, NULL);
3567c478bd9Sstevel@tonic-gate 	(void) rcm_free_handle(rhandle);
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	for (; occupant->i >= 0; occupant->i--)
3597c478bd9Sstevel@tonic-gate 		free(occupant->id[occupant->i]);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate static void
fail_rcm(hpc_occupant_info_t * occupant,rcm_handle_t * rhandle)3637c478bd9Sstevel@tonic-gate fail_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
3647c478bd9Sstevel@tonic-gate {
3657c478bd9Sstevel@tonic-gate 	DBG(1, ("fail_rcm\n"));
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	if (occupant->i == 0) /* nothing was found to ask rcm about */
3687c478bd9Sstevel@tonic-gate 		return;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	(void) rcm_notify_online_list(rhandle, occupant->id, 0, NULL);
3717c478bd9Sstevel@tonic-gate 	(void) rcm_free_handle(rhandle);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	for (; occupant->i >= 0; occupant->i--)
3747c478bd9Sstevel@tonic-gate 		free(occupant->id[occupant->i]);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate  * copied from scsi_rcm_info_table
3797c478bd9Sstevel@tonic-gate  *
3807c478bd9Sstevel@tonic-gate  *      Takes an opaque rcm_info_t pointer and a character pointer, and appends
3817c478bd9Sstevel@tonic-gate  * the rcm_info_t data in the form of a table to the given character pointer.
3827c478bd9Sstevel@tonic-gate  */
3837c478bd9Sstevel@tonic-gate static void
pci_rcm_info_table(rcm_info_t * rinfo,char ** table)3847c478bd9Sstevel@tonic-gate pci_rcm_info_table(rcm_info_t *rinfo, char **table)
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate 	int i;
3877c478bd9Sstevel@tonic-gate 	size_t w;
3887c478bd9Sstevel@tonic-gate 	size_t width = 0;
3897c478bd9Sstevel@tonic-gate 	size_t w_rsrc = 0;
3907c478bd9Sstevel@tonic-gate 	size_t w_info = 0;
3917c478bd9Sstevel@tonic-gate 	size_t table_size = 0;
3927c478bd9Sstevel@tonic-gate 	uint_t tuples = 0;
3937c478bd9Sstevel@tonic-gate 	rcm_info_tuple_t *tuple = NULL;
3947c478bd9Sstevel@tonic-gate 	char *rsrc;
3957c478bd9Sstevel@tonic-gate 	char *info;
3967c478bd9Sstevel@tonic-gate 	char *newtable;
3977c478bd9Sstevel@tonic-gate 	static char format[MAX_FORMAT];
3987c478bd9Sstevel@tonic-gate 	const char *infostr;
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	/* Protect against invalid arguments */
4017c478bd9Sstevel@tonic-gate 	if (rinfo == NULL || table == NULL)
4027c478bd9Sstevel@tonic-gate 		return;
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	/* Set localized table header strings */
4057c478bd9Sstevel@tonic-gate 	rsrc = dgettext(TEXT_DOMAIN, "Resource");
4067c478bd9Sstevel@tonic-gate 	info = dgettext(TEXT_DOMAIN, "Information");
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	/* A first pass, to size up the RCM information */
4097c478bd9Sstevel@tonic-gate 	while (tuple = rcm_info_next(rinfo, tuple)) {
4107c478bd9Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
4117c478bd9Sstevel@tonic-gate 			tuples++;
4127c478bd9Sstevel@tonic-gate 			if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
4137c478bd9Sstevel@tonic-gate 				w_rsrc = w;
4147c478bd9Sstevel@tonic-gate 			if ((w = strlen(infostr)) > w_info)
4157c478bd9Sstevel@tonic-gate 				w_info = w;
4167c478bd9Sstevel@tonic-gate 		}
4177c478bd9Sstevel@tonic-gate 	}
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	/* If nothing was sized up above, stop early */
4207c478bd9Sstevel@tonic-gate 	if (tuples == 0)
4217c478bd9Sstevel@tonic-gate 		return;
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	/* Adjust column widths for column headings */
4247c478bd9Sstevel@tonic-gate 	if ((w = strlen(rsrc)) > w_rsrc)
4257c478bd9Sstevel@tonic-gate 		w_rsrc = w;
4267c478bd9Sstevel@tonic-gate 	else if ((w_rsrc - w) % 2)
4277c478bd9Sstevel@tonic-gate 		w_rsrc++;
4287c478bd9Sstevel@tonic-gate 	if ((w = strlen(info)) > w_info)
4297c478bd9Sstevel@tonic-gate 		w_info = w;
4307c478bd9Sstevel@tonic-gate 	else if ((w_info - w) % 2)
4317c478bd9Sstevel@tonic-gate 		w_info++;
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	/*
4347c478bd9Sstevel@tonic-gate 	 * Compute the total line width of each line,
4357c478bd9Sstevel@tonic-gate 	 * accounting for intercolumn spacing.
4367c478bd9Sstevel@tonic-gate 	 */
4377c478bd9Sstevel@tonic-gate 	width = w_info + w_rsrc + 4;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	/* Allocate space for the table */
4407c478bd9Sstevel@tonic-gate 	table_size = (2 + tuples) * (width + 1) + 2;
4417c478bd9Sstevel@tonic-gate 	if (*table == NULL) {
4427c478bd9Sstevel@tonic-gate 		/* zero fill for the strcat() call below */
4437c478bd9Sstevel@tonic-gate 		*table = calloc(table_size, sizeof (char));
4447c478bd9Sstevel@tonic-gate 		if (*table == NULL)
4457c478bd9Sstevel@tonic-gate 			return;
4467c478bd9Sstevel@tonic-gate 	} else {
4477c478bd9Sstevel@tonic-gate 		newtable = realloc(*table, strlen(*table) + table_size);
4487c478bd9Sstevel@tonic-gate 		if (newtable == NULL)
4497c478bd9Sstevel@tonic-gate 			return;
4507c478bd9Sstevel@tonic-gate 		else
4517c478bd9Sstevel@tonic-gate 			*table = newtable;
4527c478bd9Sstevel@tonic-gate 	}
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	/* Place a table header into the string */
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	/* The resource header */
4577c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "\n");
4587c478bd9Sstevel@tonic-gate 	w = strlen(rsrc);
4597c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
4607c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
4617c478bd9Sstevel@tonic-gate 	(void) strcat(*table, rsrc);
4627c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++)
4637c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	/* The information header */
4667c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "  ");
4677c478bd9Sstevel@tonic-gate 	w = strlen(info);
4687c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++)
4697c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
4707c478bd9Sstevel@tonic-gate 	(void) strcat(*table, info);
4717c478bd9Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++)
4727c478bd9Sstevel@tonic-gate 		(void) strcat(*table, " ");
4737c478bd9Sstevel@tonic-gate 	/* Underline the headers */
4747c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "\n");
4757c478bd9Sstevel@tonic-gate 	for (i = 0; i < w_rsrc; i++)
4767c478bd9Sstevel@tonic-gate 		(void) strcat(*table, "-");
4777c478bd9Sstevel@tonic-gate 	(void) strcat(*table, "  ");
4787c478bd9Sstevel@tonic-gate 	for (i = 0; i < w_info; i++)
4797c478bd9Sstevel@tonic-gate 		(void) strcat(*table, "-");
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	/* Construct the format string */
4827c478bd9Sstevel@tonic-gate 	(void) snprintf(format, MAX_FORMAT, "%%-%ds  %%-%ds",
4837c478bd9Sstevel@tonic-gate 	    (int)w_rsrc, (int)w_info);
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	/* Add the tuples to the table string */
4867c478bd9Sstevel@tonic-gate 	tuple = NULL;
4877c478bd9Sstevel@tonic-gate 	while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
4887c478bd9Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
4897c478bd9Sstevel@tonic-gate 			(void) strcat(*table, "\n");
4907c478bd9Sstevel@tonic-gate 			(void) sprintf(&((*table)[strlen(*table)]),
4917c478bd9Sstevel@tonic-gate 			    format, rcm_info_rsrc(tuple),
4927c478bd9Sstevel@tonic-gate 			    infostr);
4937c478bd9Sstevel@tonic-gate 		}
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate /*
4987c478bd9Sstevel@tonic-gate  * Figure out what device is about to be unconfigured or disconnected
4997c478bd9Sstevel@tonic-gate  * and make sure rcm is ok with it.
5007c478bd9Sstevel@tonic-gate  * hangs on to a list of handles so they can then be confirmed or denied
5017c478bd9Sstevel@tonic-gate  * if either getting the occupant list or talking to rcm fails
5027c478bd9Sstevel@tonic-gate  * return CFGA_ERROR so that things can go on without rcm
5037c478bd9Sstevel@tonic-gate  */
5047c478bd9Sstevel@tonic-gate static int
check_rcm(const char * ap_id,hpc_occupant_info_t * occupant,rcm_handle_t ** rhandlep,char ** errstring,cfga_flags_t flags)5057c478bd9Sstevel@tonic-gate check_rcm(const char *ap_id, hpc_occupant_info_t *occupant,
5067c478bd9Sstevel@tonic-gate     rcm_handle_t **rhandlep, char **errstring, cfga_flags_t flags)
5077c478bd9Sstevel@tonic-gate {
5087c478bd9Sstevel@tonic-gate 	int rv;
5097c478bd9Sstevel@tonic-gate 	rcm_info_t *rinfo;
5107c478bd9Sstevel@tonic-gate 	rcm_handle_t *rhandle;
5117c478bd9Sstevel@tonic-gate 	uint_t rcmflags;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	if (get_occupants(ap_id, occupant) != 0) {
5147c478bd9Sstevel@tonic-gate 		DBG(1, ("check_rcm: failed to get occupants\n"));
5157c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
5167c478bd9Sstevel@tonic-gate 	}
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	if (occupant->i == 0) {
5197c478bd9Sstevel@tonic-gate 		DBG(1, ("check_rcm: no drivers attaching to occupants\n"));
5207c478bd9Sstevel@tonic-gate 		return (CFGA_OK);
5217c478bd9Sstevel@tonic-gate 	}
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	if (rcm_alloc_handle(NULL, 0, NULL, &rhandle)
5247c478bd9Sstevel@tonic-gate 	    != RCM_SUCCESS) {
5257c478bd9Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by rcm failure\n"));
5267c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
5277c478bd9Sstevel@tonic-gate 	}
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	rcmflags = (flags & CFGA_FLAG_FORCE) ? RCM_FORCE : 0;
5307c478bd9Sstevel@tonic-gate 	rv = rcm_request_offline_list(rhandle, occupant->id, rcmflags, &rinfo);
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	if (rv == RCM_FAILURE) {
5337c478bd9Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by rcm failure 2\n"));
5347c478bd9Sstevel@tonic-gate 		pci_rcm_info_table(rinfo, errstring);
5357c478bd9Sstevel@tonic-gate 		rcm_free_info(rinfo);
5367c478bd9Sstevel@tonic-gate 		fail_rcm(occupant, rhandle);
5377c478bd9Sstevel@tonic-gate 		return (CFGA_BUSY);
5387c478bd9Sstevel@tonic-gate 	}
5397c478bd9Sstevel@tonic-gate 	if (rv == RCM_CONFLICT) {
5407c478bd9Sstevel@tonic-gate 		DBG(1, ("check_rcm: blocked by %i\n",
5417c478bd9Sstevel@tonic-gate 		    rcm_info_pid(rinfo)));
5427c478bd9Sstevel@tonic-gate 		pci_rcm_info_table(rinfo, errstring);
5437c478bd9Sstevel@tonic-gate 		rcm_free_info(rinfo);
5447c478bd9Sstevel@tonic-gate 		(void) rcm_free_handle(rhandle);
5457c478bd9Sstevel@tonic-gate 		for (; occupant->i >= 0; occupant->i--)
5467c478bd9Sstevel@tonic-gate 			free(occupant->id[occupant->i]);
5477c478bd9Sstevel@tonic-gate 		return (CFGA_BUSY);
5487c478bd9Sstevel@tonic-gate 	}
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 	rcm_free_info(rinfo);
5517c478bd9Sstevel@tonic-gate 	*rhandlep = rhandle;
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	/* else */
5547c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
5557c478bd9Sstevel@tonic-gate }
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate /*
5597c478bd9Sstevel@tonic-gate  * Transitional Diagram:
5607c478bd9Sstevel@tonic-gate  *
5617c478bd9Sstevel@tonic-gate  *  empty		unconfigure
5627c478bd9Sstevel@tonic-gate  * (remove)	^|  (physically insert card)
5637c478bd9Sstevel@tonic-gate  *			|V
5647c478bd9Sstevel@tonic-gate  * disconnect	configure
5657c478bd9Sstevel@tonic-gate  * "-c DISCONNECT"	^|	"-c CONNECT"
5667c478bd9Sstevel@tonic-gate  *				|V	"-c CONFIGURE"
5677c478bd9Sstevel@tonic-gate  * connect	unconfigure	->	connect    configure
5687c478bd9Sstevel@tonic-gate  *						<-
5697c478bd9Sstevel@tonic-gate  *					"-c UNCONFIGURE"
5707c478bd9Sstevel@tonic-gate  *
5717c478bd9Sstevel@tonic-gate  */
5727c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5737c478bd9Sstevel@tonic-gate cfga_err_t
cfga_change_state(cfga_cmd_t state_change_cmd,const char * ap_id,const char * options,struct cfga_confirm * confp,struct cfga_msg * msgp,char ** errstring,cfga_flags_t flags)5747c478bd9Sstevel@tonic-gate cfga_change_state(cfga_cmd_t state_change_cmd, const char *ap_id,
5757c478bd9Sstevel@tonic-gate     const char *options, struct cfga_confirm *confp,
5767c478bd9Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
5777c478bd9Sstevel@tonic-gate {
5787c478bd9Sstevel@tonic-gate 	int rv;
5797c478bd9Sstevel@tonic-gate 	devctl_hdl_t		dcp;
5807c478bd9Sstevel@tonic-gate 	devctl_ap_state_t	state;
5817c478bd9Sstevel@tonic-gate 	ap_rstate_t		rs;
5827c478bd9Sstevel@tonic-gate 	ap_ostate_t		os;
5837c478bd9Sstevel@tonic-gate 	hpc_occupant_info_t occupants;
5847c478bd9Sstevel@tonic-gate 	rcm_handle_t *rhandle;
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
5877c478bd9Sstevel@tonic-gate 		return (rv);
5887c478bd9Sstevel@tonic-gate 	}
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	if (errstring != NULL)
5917c478bd9Sstevel@tonic-gate 		*errstring = NULL;
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	rv = CFGA_OK;
5947c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_change_state:(%s)\n", ap_id));
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
5977c478bd9Sstevel@tonic-gate 		if (rv == EBUSY) {
5987c478bd9Sstevel@tonic-gate 			cfga_err(errstring, CMD_ACQUIRE, ap_id, 0);
5997c478bd9Sstevel@tonic-gate 			DBG(1, ("cfga_change_state: device is busy\n"));
6007c478bd9Sstevel@tonic-gate 			rv = CFGA_BUSY;
6017c478bd9Sstevel@tonic-gate 		} else
6027c478bd9Sstevel@tonic-gate 			rv = CFGA_ERROR;
6037c478bd9Sstevel@tonic-gate 		return (rv);
6047c478bd9Sstevel@tonic-gate 	}
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
6077c478bd9Sstevel@tonic-gate 		DBG(2, ("cfga_change_state: devctl ap getstate failed\n"));
6087c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
6097c478bd9Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
6107c478bd9Sstevel@tonic-gate 		if (rv == EBUSY)
6117c478bd9Sstevel@tonic-gate 			rv = CFGA_BUSY;
6127c478bd9Sstevel@tonic-gate 		else
6137c478bd9Sstevel@tonic-gate 			rv = CFGA_ERROR;
6147c478bd9Sstevel@tonic-gate 		return (rv);
6157c478bd9Sstevel@tonic-gate 	}
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	rs = state.ap_rstate;
6187c478bd9Sstevel@tonic-gate 	os = state.ap_ostate;
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_change_state: rs is %d\n", state.ap_rstate));
6217c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_change_state: os is %d\n", state.ap_ostate));
6227c478bd9Sstevel@tonic-gate 	switch (state_change_cmd) {
6237c478bd9Sstevel@tonic-gate 	case CFGA_CMD_CONNECT:
62448c888ecSkd 		if ((rs == AP_RSTATE_EMPTY) ||
62548c888ecSkd 		    (rs == AP_RSTATE_CONNECTED) ||
6267c478bd9Sstevel@tonic-gate 		    (os == AP_OSTATE_CONFIGURED)) {
6277c478bd9Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
6287c478bd9Sstevel@tonic-gate 			rv = CFGA_INVAL;
6297c478bd9Sstevel@tonic-gate 		} else {
6307c478bd9Sstevel@tonic-gate 			/* Lets connect the slot */
6317c478bd9Sstevel@tonic-gate 			if (devctl_ap_connect(dcp, NULL) == -1) {
6327c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
6337c478bd9Sstevel@tonic-gate 				cfga_err(errstring,
6347c478bd9Sstevel@tonic-gate 				    CMD_SLOT_CONNECT, 0);
6357c478bd9Sstevel@tonic-gate 			}
6367c478bd9Sstevel@tonic-gate 		}
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 		break;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	case CFGA_CMD_DISCONNECT:
6417c478bd9Sstevel@tonic-gate 		DBG(1, ("disconnect\n"));
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 		if (os == AP_OSTATE_CONFIGURED) {
6447c478bd9Sstevel@tonic-gate 			if ((rv = check_rcm(ap_id, &occupants, &rhandle,
6457c478bd9Sstevel@tonic-gate 			    errstring, flags)) == CFGA_BUSY) {
6467c478bd9Sstevel@tonic-gate 				break;
6477c478bd9Sstevel@tonic-gate 			} else if (rv == CFGA_OK) {
6487c478bd9Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
6497c478bd9Sstevel@tonic-gate 					if (errno == EBUSY)
6507c478bd9Sstevel@tonic-gate 						rv = CFGA_BUSY;
6517c478bd9Sstevel@tonic-gate 					else
6527c478bd9Sstevel@tonic-gate 						rv = CFGA_ERROR;
6537c478bd9Sstevel@tonic-gate 					cfga_err(errstring,
6547c478bd9Sstevel@tonic-gate 					    CMD_SLOT_DISCONNECT, 0);
6557c478bd9Sstevel@tonic-gate 					fail_rcm(&occupants, rhandle);
6567c478bd9Sstevel@tonic-gate 					break;
6577c478bd9Sstevel@tonic-gate 				} else {
6587c478bd9Sstevel@tonic-gate 					confirm_rcm(&occupants, rhandle);
6597c478bd9Sstevel@tonic-gate 				}
6607c478bd9Sstevel@tonic-gate 			} else { /* rv == CFGA_ERROR */
6617c478bd9Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
6627c478bd9Sstevel@tonic-gate 					if (errno == EBUSY)
6637c478bd9Sstevel@tonic-gate 						rv = CFGA_BUSY;
6647c478bd9Sstevel@tonic-gate 					else
6657c478bd9Sstevel@tonic-gate 						rv = CFGA_ERROR;
6667c478bd9Sstevel@tonic-gate 					break;
6677c478bd9Sstevel@tonic-gate 				} else {
6687c478bd9Sstevel@tonic-gate 					rv = CFGA_OK;
6697c478bd9Sstevel@tonic-gate 				}
6707c478bd9Sstevel@tonic-gate 			}
6717c478bd9Sstevel@tonic-gate 		}
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 		if (rs == AP_RSTATE_CONNECTED) {
6747c478bd9Sstevel@tonic-gate 			if (devctl_ap_disconnect(dcp, NULL) == -1) {
6757c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
6767c478bd9Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_DISCONNECT, 0);
6777c478bd9Sstevel@tonic-gate 				break;
6787c478bd9Sstevel@tonic-gate 			}
6797c478bd9Sstevel@tonic-gate 		} else {
6807c478bd9Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
6817c478bd9Sstevel@tonic-gate 			rv = CFGA_INVAL;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 		break;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 	case CFGA_CMD_CONFIGURE:
6877c478bd9Sstevel@tonic-gate 		if (rs == AP_RSTATE_DISCONNECTED) {
6887c478bd9Sstevel@tonic-gate 			if (devctl_ap_connect(dcp, NULL) == -1) {
6897c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
6907c478bd9Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_CONNECT, 0);
6917c478bd9Sstevel@tonic-gate 				break;
6927c478bd9Sstevel@tonic-gate 			}
6937c478bd9Sstevel@tonic-gate 		}
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 		/*
6967c478bd9Sstevel@tonic-gate 		 * for multi-func device we allow multiple
6977c478bd9Sstevel@tonic-gate 		 * configure on the same slot because one
6987c478bd9Sstevel@tonic-gate 		 * func can be configured and other one won't
6997c478bd9Sstevel@tonic-gate 		 */
7007c478bd9Sstevel@tonic-gate 		if (devctl_ap_configure(dcp, NULL) == -1) {
7017c478bd9Sstevel@tonic-gate 			rv = CFGA_ERROR;
7027c478bd9Sstevel@tonic-gate 			cfga_err(errstring, CMD_SLOT_CONFIGURE, 0);
70370025d76Sjohnny 			if ((rs == AP_RSTATE_DISCONNECTED) &&
7042411ecfcSToomas Soome 			    (devctl_ap_disconnect(dcp, NULL) == -1)) {
7057c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
7067c478bd9Sstevel@tonic-gate 				cfga_err(errstring,
7077c478bd9Sstevel@tonic-gate 				    CMD_SLOT_CONFIGURE, 0);
7087c478bd9Sstevel@tonic-gate 			}
7097c478bd9Sstevel@tonic-gate 			break;
7107c478bd9Sstevel@tonic-gate 		}
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 		break;
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	case CFGA_CMD_UNCONFIGURE:
7157c478bd9Sstevel@tonic-gate 		DBG(1, ("unconfigure\n"));
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 		if (os == AP_OSTATE_CONFIGURED) {
7187c478bd9Sstevel@tonic-gate 			if ((rv = check_rcm(ap_id, &occupants, &rhandle,
7197c478bd9Sstevel@tonic-gate 			    errstring, flags)) == CFGA_BUSY) {
7207c478bd9Sstevel@tonic-gate 				break;
7217c478bd9Sstevel@tonic-gate 			} else if (rv == CFGA_OK) {
7227c478bd9Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
7237c478bd9Sstevel@tonic-gate 					if (errno == EBUSY)
7247c478bd9Sstevel@tonic-gate 						rv = CFGA_BUSY;
7257c478bd9Sstevel@tonic-gate 					else {
7267c478bd9Sstevel@tonic-gate 						if (errno == ENOTSUP)
7277c478bd9Sstevel@tonic-gate 							rv = CFGA_OPNOTSUPP;
7287c478bd9Sstevel@tonic-gate 						else
7297c478bd9Sstevel@tonic-gate 							rv = CFGA_ERROR;
7307c478bd9Sstevel@tonic-gate 					}
7317c478bd9Sstevel@tonic-gate 					cfga_err(errstring,
7327c478bd9Sstevel@tonic-gate 					    CMD_SLOT_UNCONFIGURE, 0);
7337c478bd9Sstevel@tonic-gate 					fail_rcm(&occupants, rhandle);
7347c478bd9Sstevel@tonic-gate 				} else {
7357c478bd9Sstevel@tonic-gate 					confirm_rcm(&occupants, rhandle);
7367c478bd9Sstevel@tonic-gate 				}
7377c478bd9Sstevel@tonic-gate 			} else { /* rv == CFGA_ERROR */
7387c478bd9Sstevel@tonic-gate 				if (devctl_ap_unconfigure(dcp, NULL) == -1) {
7397c478bd9Sstevel@tonic-gate 					if (errno == EBUSY)
7407c478bd9Sstevel@tonic-gate 						rv = CFGA_BUSY;
7417c478bd9Sstevel@tonic-gate 					else {
7427c478bd9Sstevel@tonic-gate 						if (errno == ENOTSUP)
7437c478bd9Sstevel@tonic-gate 							rv = CFGA_OPNOTSUPP;
7447c478bd9Sstevel@tonic-gate 						else
7457c478bd9Sstevel@tonic-gate 							rv = CFGA_ERROR;
7467c478bd9Sstevel@tonic-gate 					}
7477c478bd9Sstevel@tonic-gate 					cfga_err(errstring,
7487c478bd9Sstevel@tonic-gate 					    CMD_SLOT_UNCONFIGURE, 0);
7497c478bd9Sstevel@tonic-gate 				} else {
7507c478bd9Sstevel@tonic-gate 					rv = CFGA_OK;
7517c478bd9Sstevel@tonic-gate 				}
7527c478bd9Sstevel@tonic-gate 			}
7537c478bd9Sstevel@tonic-gate 		} else {
7547c478bd9Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
7557c478bd9Sstevel@tonic-gate 			rv = CFGA_INVAL;
7567c478bd9Sstevel@tonic-gate 		}
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 		DBG(1, ("uncofigure rv:(%i)\n", rv));
7597c478bd9Sstevel@tonic-gate 		break;
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	case CFGA_CMD_LOAD:
7627c478bd9Sstevel@tonic-gate 		if ((os == AP_OSTATE_UNCONFIGURED) &&
7637c478bd9Sstevel@tonic-gate 		    (rs == AP_RSTATE_DISCONNECTED)) {
7647c478bd9Sstevel@tonic-gate 			if (devctl_ap_insert(dcp, NULL) == -1) {
7657c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
7667c478bd9Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_INSERT, 0);
7677c478bd9Sstevel@tonic-gate 			}
7687c478bd9Sstevel@tonic-gate 		} else {
7697c478bd9Sstevel@tonic-gate 			cfga_err(errstring, ERR_AP_ERR, 0);
7707c478bd9Sstevel@tonic-gate 			rv = CFGA_INVAL;
7717c478bd9Sstevel@tonic-gate 		}
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate 		break;
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	case CFGA_CMD_UNLOAD:
7767c478bd9Sstevel@tonic-gate 		if ((os == AP_OSTATE_UNCONFIGURED) &&
7777c478bd9Sstevel@tonic-gate 		    (rs == AP_RSTATE_DISCONNECTED)) {
7787c478bd9Sstevel@tonic-gate 			if (devctl_ap_remove(dcp, NULL) == -1) {
7797c478bd9Sstevel@tonic-gate 				rv = CFGA_ERROR;
7807c478bd9Sstevel@tonic-gate 				cfga_err(errstring, CMD_SLOT_REMOVE, 0);
7817c478bd9Sstevel@tonic-gate 			}
7827c478bd9Sstevel@tonic-gate 		} else {
7837c478bd9Sstevel@tonic-gate 				cfga_err(errstring, ERR_AP_ERR, 0);
7847c478bd9Sstevel@tonic-gate 				rv = CFGA_INVAL;
7857c478bd9Sstevel@tonic-gate 			}
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 		break;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 	default:
7907c478bd9Sstevel@tonic-gate 		rv = CFGA_OPNOTSUPP;
7917c478bd9Sstevel@tonic-gate 		break;
7927c478bd9Sstevel@tonic-gate 	}
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	devctl_release((devctl_hdl_t)dcp);
7957c478bd9Sstevel@tonic-gate 	return (rv);
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate /*
7997c478bd9Sstevel@tonic-gate  * Building iocdatat to pass it to nexus
8007c478bd9Sstevel@tonic-gate  *
8017c478bd9Sstevel@tonic-gate  *	iocdata->cmd ==  HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT
8027c478bd9Sstevel@tonic-gate  *			HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG
8037c478bd9Sstevel@tonic-gate  *			HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE
8047c478bd9Sstevel@tonic-gate  *			HPC_CTRL_GET_SLOT_STATE/HPC_CTRL_GET_SLOT_INFO
8057c478bd9Sstevel@tonic-gate  *			HPC_CTRL_DEV_CONFIGURE/HPC_CTRL_DEV_UNCONFIGURE
8067c478bd9Sstevel@tonic-gate  *			HPC_CTRL_GET_BOARD_TYPE
8077c478bd9Sstevel@tonic-gate  *
8087c478bd9Sstevel@tonic-gate  */
8097c478bd9Sstevel@tonic-gate static void
build_control_data(struct hpc_control_data * iocdata,uint_t cmd,void * retdata)8107c478bd9Sstevel@tonic-gate build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
8117c478bd9Sstevel@tonic-gate     void *retdata)
8127c478bd9Sstevel@tonic-gate {
8137c478bd9Sstevel@tonic-gate 	iocdata->cmd = cmd;
8147c478bd9Sstevel@tonic-gate 	iocdata->data = retdata;
8157c478bd9Sstevel@tonic-gate }
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate /*
8187c478bd9Sstevel@tonic-gate  * building logical name from ap_id
8197c478bd9Sstevel@tonic-gate  */
8207c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
8217c478bd9Sstevel@tonic-gate static void
get_logical_name(const char * ap_id,char * buf,dev_t rdev)8227c478bd9Sstevel@tonic-gate get_logical_name(const char *ap_id, char *buf, dev_t rdev)
8237c478bd9Sstevel@tonic-gate {
8247c478bd9Sstevel@tonic-gate 	char *bufptr, *bufptr2, *pci, *apid;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 	DBG(1, ("get_logical_name: %s\n", ap_id));
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 	if ((apid = malloc(MAXPATHLEN)) == NULL) {
8297c478bd9Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
8307c478bd9Sstevel@tonic-gate 		return;
8317c478bd9Sstevel@tonic-gate 	}
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	(void) memset(apid, 0, MAXPATHLEN);
8347c478bd9Sstevel@tonic-gate 	(void) strncpy(apid, ap_id, strlen(ap_id));
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate 	/* needs to look for last /, not first */
8377c478bd9Sstevel@tonic-gate 	bufptr = strrchr(apid, '/');
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 	bufptr2 = strrchr(apid, ':');
8407c478bd9Sstevel@tonic-gate 	pci = ++bufptr;
8417c478bd9Sstevel@tonic-gate 	bufptr = strchr(pci, ',');
8427c478bd9Sstevel@tonic-gate 	if (bufptr != NULL) {
8437c478bd9Sstevel@tonic-gate 		*bufptr = '\0';
8447c478bd9Sstevel@tonic-gate 	}
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	bufptr = strchr(pci, '@');
8477c478bd9Sstevel@tonic-gate 	if (bufptr != NULL) {
8487c478bd9Sstevel@tonic-gate 		*bufptr = '\0';
8497c478bd9Sstevel@tonic-gate 		bufptr++;
8507c478bd9Sstevel@tonic-gate 	}
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 	DBG(1, ("%s\n%s\n%s\n", pci, bufptr, bufptr2));
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	(void) strcat(buf, pci);
8557c478bd9Sstevel@tonic-gate 	(void) strcat(buf, bufptr);
8567c478bd9Sstevel@tonic-gate 	(void) strcat(buf, bufptr2);
8577c478bd9Sstevel@tonic-gate 	free(apid);
8587c478bd9Sstevel@tonic-gate }
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate static cfga_err_t
prt_led_mode(const char * ap_id,int repeat,char ** errstring,struct cfga_msg * msgp)8617c478bd9Sstevel@tonic-gate prt_led_mode(const char *ap_id, int repeat, char **errstring,
8627c478bd9Sstevel@tonic-gate     struct cfga_msg *msgp)
8637c478bd9Sstevel@tonic-gate {
8647c478bd9Sstevel@tonic-gate 	hpc_led_info_t	power_led_info = {HPC_POWER_LED, 0};
8657c478bd9Sstevel@tonic-gate 	hpc_led_info_t	fault_led_info = {HPC_FAULT_LED, 0};
8667c478bd9Sstevel@tonic-gate 	hpc_led_info_t	attn_led_info = {HPC_ATTN_LED, 0};
8677c478bd9Sstevel@tonic-gate 	hpc_led_info_t	active_led_info = {HPC_ACTIVE_LED, 0};
8687c478bd9Sstevel@tonic-gate 	struct hpc_control_data iocdata;
8697c478bd9Sstevel@tonic-gate 	struct stat	statbuf;
8707c478bd9Sstevel@tonic-gate 	char  *buff;
8717c478bd9Sstevel@tonic-gate 	int	fd;
8727c478bd9Sstevel@tonic-gate 	hpc_slot_info_t		slot_info;
8737c478bd9Sstevel@tonic-gate 	char *cp, line[MAXLINE];
8747c478bd9Sstevel@tonic-gate 	int len = MAXLINE;
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	DBG(1, ("prt_led_mod function\n"));
8777c478bd9Sstevel@tonic-gate 	if (!repeat)
8787c478bd9Sstevel@tonic-gate 		cfga_msg(msgp, "Ap_Id\t\t\tLed");
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
8817c478bd9Sstevel@tonic-gate 		DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
8827c478bd9Sstevel@tonic-gate 		DBG_F(2, (stderr, "open on %s failed\n", ap_id));
8837c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_OPEN,  ap_id, 0);
8847c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
8857c478bd9Sstevel@tonic-gate 	}
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 	if (fstat(fd, &statbuf) == -1) {
8887c478bd9Sstevel@tonic-gate 		DBG(2, ("fstat = ap_id%s, fd%d\n", ap_id, fd));
8897c478bd9Sstevel@tonic-gate 		DBG_F(2, (stderr, "fstat on %s failed\n", ap_id));
8907c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_FSTAT, ap_id, 0);
8917c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
8927c478bd9Sstevel@tonic-gate 	}
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 	if ((buff = malloc(MAXPATHLEN)) == NULL) {
8957c478bd9Sstevel@tonic-gate 		cfga_err(errstring, "malloc ", 0);
8967c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
8977c478bd9Sstevel@tonic-gate 	}
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 	(void) memset(buff, 0, MAXPATHLEN);
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 	DBG(1, ("ioctl boardtype\n"));
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
9047c478bd9Sstevel@tonic-gate 	    (void *)&slot_info);
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9077c478bd9Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
9087c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl failed slotinfo: %s\n",
9097c478bd9Sstevel@tonic-gate 		    slot_info.pci_slot_name));
9107c478bd9Sstevel@tonic-gate 	} else {
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 		/*
9137c478bd9Sstevel@tonic-gate 		 * the driver will report back things like hpc0_slot0
9147c478bd9Sstevel@tonic-gate 		 * this needs to be changed to things like pci1:hpc0_slot0
9157c478bd9Sstevel@tonic-gate 		 */
9167c478bd9Sstevel@tonic-gate 		if (fix_ap_name(buff, ap_id, slot_info.pci_slot_name,
9177c478bd9Sstevel@tonic-gate 		    errstring) != CFGA_OK) {
9187c478bd9Sstevel@tonic-gate 			free(buff);
9197c478bd9Sstevel@tonic-gate 			(void) close(fd);
9207c478bd9Sstevel@tonic-gate 			return (CFGA_ERROR);
9217c478bd9Sstevel@tonic-gate 		}
9227c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl slotinfo: %s\n", buff));
9237c478bd9Sstevel@tonic-gate 	}
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate 	cp = line;
9267c478bd9Sstevel@tonic-gate 	(void) snprintf(cp, len, "%s\t\t", buff);
9277c478bd9Sstevel@tonic-gate 	len -= strlen(cp);
9287c478bd9Sstevel@tonic-gate 	cp += strlen(cp);
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate 	free(buff);
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &power_led_info);
9337c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9347c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9357c478bd9Sstevel@tonic-gate 		    led_strs[power_led_info.led], cfga_strs[UNKNOWN]);
9367c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9377c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9387c478bd9Sstevel@tonic-gate 	} else {
9397c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,", led_strs[power_led_info.led],
9407c478bd9Sstevel@tonic-gate 		    mode_strs[power_led_info.state]);
9417c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9427c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9437c478bd9Sstevel@tonic-gate 	}
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[power_led_info.led], power_led_info.state));
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &fault_led_info);
9487c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9497c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9507c478bd9Sstevel@tonic-gate 		    led_strs[fault_led_info.led], cfga_strs[UNKNOWN]);
9517c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9527c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9537c478bd9Sstevel@tonic-gate 	} else {
9547c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9557c478bd9Sstevel@tonic-gate 		    led_strs[fault_led_info.led],
9567c478bd9Sstevel@tonic-gate 		    mode_strs[fault_led_info.state]);
9577c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9587c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9597c478bd9Sstevel@tonic-gate 	}
9607c478bd9Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[fault_led_info.led], fault_led_info.state));
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &attn_led_info);
9637c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9647c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9657c478bd9Sstevel@tonic-gate 		    led_strs[attn_led_info.led], cfga_strs[UNKNOWN]);
9667c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9677c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9687c478bd9Sstevel@tonic-gate 	} else {
9697c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s,",
9707c478bd9Sstevel@tonic-gate 		    led_strs[attn_led_info.led],
9717c478bd9Sstevel@tonic-gate 		    mode_strs[attn_led_info.state]);
9727c478bd9Sstevel@tonic-gate 		len -= strlen(cp);
9737c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
9747c478bd9Sstevel@tonic-gate 	}
9757c478bd9Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[attn_led_info.led], attn_led_info.state));
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &active_led_info);
9787c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
9797c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s", led_strs[active_led_info.led],
9807c478bd9Sstevel@tonic-gate 		    cfga_strs[UNKNOWN]);
9817c478bd9Sstevel@tonic-gate 	} else {
9827c478bd9Sstevel@tonic-gate 		(void) snprintf(cp, len, "%s=%s",
9837c478bd9Sstevel@tonic-gate 		    led_strs[active_led_info.led],
9847c478bd9Sstevel@tonic-gate 		    mode_strs[active_led_info.state]);
9857c478bd9Sstevel@tonic-gate 	}
9867c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, line);	/* print the message */
9877c478bd9Sstevel@tonic-gate 	DBG(1, ("%s:%d\n", led_strs[active_led_info.led],
9887c478bd9Sstevel@tonic-gate 	    active_led_info.state));
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 	(void) close(fd);
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9967c478bd9Sstevel@tonic-gate cfga_err_t
cfga_private_func(const char * function,const char * ap_id,const char * options,struct cfga_confirm * confp,struct cfga_msg * msgp,char ** errstring,cfga_flags_t flags)9977c478bd9Sstevel@tonic-gate cfga_private_func(const char *function, const char *ap_id,
9987c478bd9Sstevel@tonic-gate     const char *options, struct cfga_confirm *confp,
9997c478bd9Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate 	char *str;
10027c478bd9Sstevel@tonic-gate 	int   len, fd, i = 0, repeat = 0;
10037c478bd9Sstevel@tonic-gate 	char buf[MAXNAMELEN];
10047c478bd9Sstevel@tonic-gate 	char ptr;
10057c478bd9Sstevel@tonic-gate 	hpc_led_info_t	led_info;
10067c478bd9Sstevel@tonic-gate 	struct hpc_control_data	iocdata;
10077c478bd9Sstevel@tonic-gate 	cfga_err_t rv;
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 	DBG(1, ("cfgadm_private_func: ap_id:%s\n", ap_id));
10107c478bd9Sstevel@tonic-gate 	DBG(2, ("  options: %s\n", (options == NULL)?"null":options));
10117c478bd9Sstevel@tonic-gate 	DBG(2, ("  confp: %x\n", confp));
10127c478bd9Sstevel@tonic-gate 	DBG(2, ("  cfga_msg: %x\n", cfga_msg));
10137c478bd9Sstevel@tonic-gate 	DBG(2, ("  flag: %d\n", flags));
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
10167c478bd9Sstevel@tonic-gate 		return (rv);
10177c478bd9Sstevel@tonic-gate 	}
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate 	if (private_check == confp)
10207c478bd9Sstevel@tonic-gate 		repeat = 1;
10217c478bd9Sstevel@tonic-gate 	else
10227c478bd9Sstevel@tonic-gate 		private_check = (void*)confp;
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	/* XXX change const 6 to func_str[i] != NULL */
10257c478bd9Sstevel@tonic-gate 	for (i = 0, str = func_strs[i], len = strlen(str); i < 6; i++) {
10267c478bd9Sstevel@tonic-gate 		str = func_strs[i];
10277c478bd9Sstevel@tonic-gate 		len = strlen(str);
10287c478bd9Sstevel@tonic-gate 		if (strncmp(function, str, len) == 0)
10297c478bd9Sstevel@tonic-gate 			break;
10307c478bd9Sstevel@tonic-gate 	}
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate 	switch (i) {
10337c478bd9Sstevel@tonic-gate 		case ENABLE_SLOT:
10347c478bd9Sstevel@tonic-gate 			build_control_data(&iocdata,
10352411ecfcSToomas Soome 			    HPC_CTRL_ENABLE_SLOT, 0);
10367c478bd9Sstevel@tonic-gate 			break;
10377c478bd9Sstevel@tonic-gate 		case DISABLE_SLOT:
10387c478bd9Sstevel@tonic-gate 			build_control_data(&iocdata,
10392411ecfcSToomas Soome 			    HPC_CTRL_DISABLE_SLOT, 0);
10407c478bd9Sstevel@tonic-gate 			break;
10417c478bd9Sstevel@tonic-gate 		case ENABLE_AUTOCNF:
10427c478bd9Sstevel@tonic-gate 			build_control_data(&iocdata,
10432411ecfcSToomas Soome 			    HPC_CTRL_ENABLE_AUTOCFG, 0);
10447c478bd9Sstevel@tonic-gate 			break;
10457c478bd9Sstevel@tonic-gate 		case DISABLE_AUTOCNF:
10467c478bd9Sstevel@tonic-gate 			build_control_data(&iocdata,
10472411ecfcSToomas Soome 			    HPC_CTRL_DISABLE_AUTOCFG, 0);
10487c478bd9Sstevel@tonic-gate 			break;
10497c478bd9Sstevel@tonic-gate 		case LED:
10507c478bd9Sstevel@tonic-gate 			/* set mode */
10517c478bd9Sstevel@tonic-gate 			ptr = function[len++];
10527c478bd9Sstevel@tonic-gate 			if (ptr == '=') {
10537c478bd9Sstevel@tonic-gate 				str = (char *)function;
10547c478bd9Sstevel@tonic-gate 				for (str = (str+len++), i = 0; *str != ',';
10557c478bd9Sstevel@tonic-gate 				    i++, str++) {
10567c478bd9Sstevel@tonic-gate 					if (i == (MAXNAMELEN - 1))
10577c478bd9Sstevel@tonic-gate 						break;
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 					buf[i] = *str;
10607c478bd9Sstevel@tonic-gate 					DBG_F(2, (stdout, "%c\n", buf[i]));
10617c478bd9Sstevel@tonic-gate 				}
10627c478bd9Sstevel@tonic-gate 				buf[i] = '\0'; str++;
10637c478bd9Sstevel@tonic-gate 				DBG(2, ("buf = %s\n", buf));
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 				/* ACTIVE=3,ATTN=2,POWER=1,FAULT=0 */
10667c478bd9Sstevel@tonic-gate 				if (strcmp(buf, led_strs[POWER]) == 0)
10677c478bd9Sstevel@tonic-gate 					led_info.led = HPC_POWER_LED;
10687c478bd9Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[FAULT]) == 0)
10697c478bd9Sstevel@tonic-gate 					led_info.led = HPC_FAULT_LED;
10707c478bd9Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[ATTN]) == 0)
10717c478bd9Sstevel@tonic-gate 					led_info.led = HPC_ATTN_LED;
10727c478bd9Sstevel@tonic-gate 				else if (strcmp(buf, led_strs[ACTIVE]) == 0)
10737c478bd9Sstevel@tonic-gate 					led_info.led = HPC_ACTIVE_LED;
10747c478bd9Sstevel@tonic-gate 				else return (CFGA_INVAL);
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 				len = strlen(func_strs[MODE]);
10777c478bd9Sstevel@tonic-gate 				if ((strncmp(str, func_strs[MODE], len) == 0) &&
10787c478bd9Sstevel@tonic-gate 				    (*(str+(len)) == '=')) {
10792411ecfcSToomas Soome 					for (str = (str+(++len)), i = 0;
108021f023dfSToomas Soome 					    *str != '\0'; i++, str++) {
10817c478bd9Sstevel@tonic-gate 						buf[i] = *str;
10822411ecfcSToomas Soome 					}
10837c478bd9Sstevel@tonic-gate 				}
10847c478bd9Sstevel@tonic-gate 				buf[i] = '\0';
10857c478bd9Sstevel@tonic-gate 				DBG(2, ("buf_mode= %s\n", buf));
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 				/* ON = 1, OFF = 0 */
10887c478bd9Sstevel@tonic-gate 				if (strcmp(buf, mode_strs[ON]) == 0)
10897c478bd9Sstevel@tonic-gate 					led_info.state = HPC_LED_ON;
10907c478bd9Sstevel@tonic-gate 				else if (strcmp(buf, mode_strs[OFF]) == 0)
10917c478bd9Sstevel@tonic-gate 					led_info.state = HPC_LED_OFF;
10927c478bd9Sstevel@tonic-gate 				else if (strcmp(buf, mode_strs[BLINK]) == 0)
10937c478bd9Sstevel@tonic-gate 					led_info.state = HPC_LED_BLINK;
10947c478bd9Sstevel@tonic-gate 				else return (CFGA_INVAL);
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate 				/* sendin  */
10977c478bd9Sstevel@tonic-gate 				build_control_data(&iocdata,
10987c478bd9Sstevel@tonic-gate 				    HPC_CTRL_SET_LED_STATE,
10997c478bd9Sstevel@tonic-gate 				    (void *)&led_info);
11007c478bd9Sstevel@tonic-gate 				break;
11017c478bd9Sstevel@tonic-gate 			} else if (ptr == '\0') {
11027c478bd9Sstevel@tonic-gate 				/* print mode */
11037c478bd9Sstevel@tonic-gate 				DBG(1, ("Print mode\n"));
11047c478bd9Sstevel@tonic-gate 				return (prt_led_mode(ap_id, repeat, errstring,
11057c478bd9Sstevel@tonic-gate 				    msgp));
11067c478bd9Sstevel@tonic-gate 			}
11072411ecfcSToomas Soome 			/* FALLTHROUGH */
11087c478bd9Sstevel@tonic-gate 		default:
11097c478bd9Sstevel@tonic-gate 			DBG(1, ("default\n"));
11107c478bd9Sstevel@tonic-gate 			errno = EINVAL;
11117c478bd9Sstevel@tonic-gate 			return (CFGA_INVAL);
11127c478bd9Sstevel@tonic-gate 	}
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
11157c478bd9Sstevel@tonic-gate 		DBG(1, ("open failed\n"));
11167c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
11177c478bd9Sstevel@tonic-gate 	}
11187c478bd9Sstevel@tonic-gate 
11197c478bd9Sstevel@tonic-gate 	DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
11227c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl failed\n"));
11237c478bd9Sstevel@tonic-gate 		(void) close(fd);
11247c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
11257c478bd9Sstevel@tonic-gate 	}
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate 	(void) close(fd);
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
11307c478bd9Sstevel@tonic-gate }
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate /*ARGSUSED*/
cfga_test(const char * ap_id,const char * options,struct cfga_msg * msgp,char ** errstring,cfga_flags_t flags)11337c478bd9Sstevel@tonic-gate cfga_err_t cfga_test(const char *ap_id, const char *options,
11347c478bd9Sstevel@tonic-gate     struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
11357c478bd9Sstevel@tonic-gate {
11367c478bd9Sstevel@tonic-gate 	cfga_err_t rv;
11377c478bd9Sstevel@tonic-gate 	if (errstring != NULL)
11387c478bd9Sstevel@tonic-gate 		*errstring = NULL;
11397c478bd9Sstevel@tonic-gate 
11407c478bd9Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
11417c478bd9Sstevel@tonic-gate 		return (rv);
11427c478bd9Sstevel@tonic-gate 	}
11437c478bd9Sstevel@tonic-gate 
11447c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_test:(%s)\n", ap_id));
11457c478bd9Sstevel@tonic-gate 	/* will need to implement pci CTRL command */
11467c478bd9Sstevel@tonic-gate 	return (CFGA_NOTSUPP);
11477c478bd9Sstevel@tonic-gate }
11487c478bd9Sstevel@tonic-gate 
11497c478bd9Sstevel@tonic-gate static int
fixup_slotname(int rval,int * intp,struct searcharg * slotarg)11507c478bd9Sstevel@tonic-gate fixup_slotname(int rval, int *intp, struct searcharg *slotarg)
11517c478bd9Sstevel@tonic-gate {
11527c478bd9Sstevel@tonic-gate 
11537c478bd9Sstevel@tonic-gate /*
11547c478bd9Sstevel@tonic-gate  * The slot-names property describes the external labeling of add-in slots.
11557c478bd9Sstevel@tonic-gate  * This property is an encoded array, an integer followed by a list of
11567c478bd9Sstevel@tonic-gate  * strings. The return value from di_prop_lookup_ints for slot-names is -1.
11577c478bd9Sstevel@tonic-gate  * The expected return value should be the number of elements.
11587c478bd9Sstevel@tonic-gate  * Di_prop_decode_common does not decode encoded data from software,
11597c478bd9Sstevel@tonic-gate  * such as the solaris device tree, unlike from the prom.
11607c478bd9Sstevel@tonic-gate  * Di_prop_decode_common takes the size of the encoded data and mods
11617c478bd9Sstevel@tonic-gate  * it with the size of int. The size of the encoded data for slot-names is 9
11627c478bd9Sstevel@tonic-gate  * and the size of int is 4, yielding a non zero result. A value of -1 is used
11637c478bd9Sstevel@tonic-gate  * to indicate that the number of elements can not be determined.
11647c478bd9Sstevel@tonic-gate  * Di_prop_decode_common can be modified to decode encoded data from the solaris
11657c478bd9Sstevel@tonic-gate  * device tree.
11667c478bd9Sstevel@tonic-gate  */
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	if ((slotarg->slt_name_src == PROM_SLT_NAME) && (rval == -1)) {
11697c478bd9Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
11707c478bd9Sstevel@tonic-gate 	} else {
11717c478bd9Sstevel@tonic-gate 		int i;
11727c478bd9Sstevel@tonic-gate 		char *tmptr = (char *)(intp+1);
11737c478bd9Sstevel@tonic-gate 		DBG(1, ("slot-bitmask: %x \n", *intp));
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate 		rval = (rval -1) * 4;
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 		for (i = 0; i <= slotarg->minor; i++) {
11787c478bd9Sstevel@tonic-gate 			DBG(2, ("curr slot-name: %s \n", tmptr));
11797c478bd9Sstevel@tonic-gate 
11807c478bd9Sstevel@tonic-gate 			if (i >= MAXDEVS)
11817c478bd9Sstevel@tonic-gate 				return (DI_WALK_TERMINATE);
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 			if ((*intp >> i) & 1) {
11847c478bd9Sstevel@tonic-gate 				/* assign tmptr */
11857c478bd9Sstevel@tonic-gate 				DBG(2, ("slot-name: %s \n", tmptr));
11867c478bd9Sstevel@tonic-gate 				if (i == slotarg->minor)
11877c478bd9Sstevel@tonic-gate 					(void) strcpy(slotarg->slotnames[i],
11887c478bd9Sstevel@tonic-gate 					    tmptr);
11897c478bd9Sstevel@tonic-gate 				/* wind tmptr to next \0 */
11907c478bd9Sstevel@tonic-gate 				while (*tmptr != '\0') {
11917c478bd9Sstevel@tonic-gate 					tmptr++;
11927c478bd9Sstevel@tonic-gate 				}
11937c478bd9Sstevel@tonic-gate 				tmptr++;
11947c478bd9Sstevel@tonic-gate 			} else {
11957c478bd9Sstevel@tonic-gate 				/* point at unknown string */
11967c478bd9Sstevel@tonic-gate 				if (i == slotarg->minor)
11977c478bd9Sstevel@tonic-gate 					(void) strcpy(slotarg->slotnames[i],
11987c478bd9Sstevel@tonic-gate 					    "unknown");
11997c478bd9Sstevel@tonic-gate 			}
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 	}
12027c478bd9Sstevel@tonic-gate 	return (DI_WALK_TERMINATE);
12037c478bd9Sstevel@tonic-gate }
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate static int
find_slotname(di_node_t din,di_minor_t dim,void * arg)12067c478bd9Sstevel@tonic-gate find_slotname(di_node_t din, di_minor_t dim, void *arg)
12077c478bd9Sstevel@tonic-gate {
12087c478bd9Sstevel@tonic-gate 	struct searcharg *slotarg = (struct searcharg *)arg;
12097c478bd9Sstevel@tonic-gate 	di_prom_handle_t ph = (di_prom_handle_t)slotarg->promp;
12107c478bd9Sstevel@tonic-gate 	di_prom_prop_t	prom_prop;
12117c478bd9Sstevel@tonic-gate 	di_prop_t	solaris_prop;
12127c478bd9Sstevel@tonic-gate 	int *intp, rval;
12137c478bd9Sstevel@tonic-gate 	char *devname;
12147c478bd9Sstevel@tonic-gate 	char fulldevname[MAXNAMELEN];
12157c478bd9Sstevel@tonic-gate 
12167c478bd9Sstevel@tonic-gate 	slotarg->minor = dim->dev_minor % 256;
12177c478bd9Sstevel@tonic-gate 
12187c478bd9Sstevel@tonic-gate 	DBG(2, ("minor number:(%i)\n", slotarg->minor));
12197c478bd9Sstevel@tonic-gate 	DBG(2, ("hot plug slots found so far:(%i)\n", 0));
12207c478bd9Sstevel@tonic-gate 
12217c478bd9Sstevel@tonic-gate 	if ((devname = di_devfs_path(din)) != NULL) {
12227c478bd9Sstevel@tonic-gate 		(void) snprintf(fulldevname, MAXNAMELEN,
12237c478bd9Sstevel@tonic-gate 		    "/devices%s:%s", devname, di_minor_name(dim));
12247c478bd9Sstevel@tonic-gate 		di_devfs_path_free(devname);
12257c478bd9Sstevel@tonic-gate 	}
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	if (strcmp(fulldevname, slotarg->devpath) == 0) {
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate 		/*
12307c478bd9Sstevel@tonic-gate 		 * Check the Solaris device tree first
12317c478bd9Sstevel@tonic-gate 		 * in the case of a DR operation
12327c478bd9Sstevel@tonic-gate 		 */
12337c478bd9Sstevel@tonic-gate 		solaris_prop = di_prop_hw_next(din, DI_PROP_NIL);
12347c478bd9Sstevel@tonic-gate 		while (solaris_prop != DI_PROP_NIL) {
12357c478bd9Sstevel@tonic-gate 			if (strcmp("slot-names", di_prop_name(solaris_prop))
12367c478bd9Sstevel@tonic-gate 			    == 0) {
12377c478bd9Sstevel@tonic-gate 				rval = di_prop_lookup_ints(DDI_DEV_T_ANY,
12387c478bd9Sstevel@tonic-gate 				    din, di_prop_name(solaris_prop), &intp);
12397c478bd9Sstevel@tonic-gate 				slotarg->slt_name_src = SOLARIS_SLT_NAME;
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 				return (fixup_slotname(rval, intp, slotarg));
12427c478bd9Sstevel@tonic-gate 			}
12437c478bd9Sstevel@tonic-gate 			solaris_prop = di_prop_hw_next(din, solaris_prop);
12447c478bd9Sstevel@tonic-gate 		}
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 		/*
12477c478bd9Sstevel@tonic-gate 		 * Check the prom device tree which is populated at boot.
12487c478bd9Sstevel@tonic-gate 		 * If this fails, give up and set the slot name to null.
12497c478bd9Sstevel@tonic-gate 		 */
12507c478bd9Sstevel@tonic-gate 		prom_prop = di_prom_prop_next(ph, din, DI_PROM_PROP_NIL);
12517c478bd9Sstevel@tonic-gate 		while (prom_prop != DI_PROM_PROP_NIL) {
12527c478bd9Sstevel@tonic-gate 			if (strcmp("slot-names", di_prom_prop_name(prom_prop))
12537c478bd9Sstevel@tonic-gate 			    == 0) {
12547c478bd9Sstevel@tonic-gate 				rval = di_prom_prop_lookup_ints(ph,
12557c478bd9Sstevel@tonic-gate 				    din, di_prom_prop_name(prom_prop), &intp);
12567c478bd9Sstevel@tonic-gate 				slotarg->slt_name_src = PROM_SLT_NAME;
12577c478bd9Sstevel@tonic-gate 
12587c478bd9Sstevel@tonic-gate 				return (fixup_slotname(rval, intp, slotarg));
12597c478bd9Sstevel@tonic-gate 			}
12607c478bd9Sstevel@tonic-gate 			prom_prop = di_prom_prop_next(ph, din, prom_prop);
12617c478bd9Sstevel@tonic-gate 		}
12627c478bd9Sstevel@tonic-gate 		*slotarg->slotnames[slotarg->minor] = '\0';
12637c478bd9Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
12647c478bd9Sstevel@tonic-gate 	} else
12657c478bd9Sstevel@tonic-gate 		return (DI_WALK_CONTINUE);
12667c478bd9Sstevel@tonic-gate }
12677c478bd9Sstevel@tonic-gate 
12687c478bd9Sstevel@tonic-gate static int
find_physical_slot_names(const char * devcomp,struct searcharg * slotarg)12697c478bd9Sstevel@tonic-gate find_physical_slot_names(const char *devcomp, struct searcharg *slotarg)
12707c478bd9Sstevel@tonic-gate {
12717c478bd9Sstevel@tonic-gate 	di_node_t root_node;
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate 	DBG(1, ("find_physical_slot_names\n"));
12747c478bd9Sstevel@tonic-gate 
12752411ecfcSToomas Soome 	if ((root_node = di_init("/", DINFOCPYALL|DINFOPATH)) == DI_NODE_NIL) {
12767c478bd9Sstevel@tonic-gate 		DBG(1, ("di_init() failed\n"));
127721f023dfSToomas Soome 		return (-1);
12787c478bd9Sstevel@tonic-gate 	}
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 	slotarg->devpath = (char *)devcomp;
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate 	if ((slotarg->promp = di_prom_init()) == DI_PROM_HANDLE_NIL) {
12837c478bd9Sstevel@tonic-gate 		DBG(1, ("di_prom_init() failed\n"));
12847c478bd9Sstevel@tonic-gate 		di_fini(root_node);
128521f023dfSToomas Soome 		return (-1);
12867c478bd9Sstevel@tonic-gate 	}
12877c478bd9Sstevel@tonic-gate 
12887c478bd9Sstevel@tonic-gate 	(void) di_walk_minor(root_node, "ddi_ctl:attachment_point:pci",
12892411ecfcSToomas Soome 	    0, (void *)slotarg, find_slotname);
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate 	di_prom_fini(slotarg->promp);
12927c478bd9Sstevel@tonic-gate 	di_fini(root_node);
1293014ec826SToomas Soome 	if (*slotarg->slotnames[0] != '\0')
12947c478bd9Sstevel@tonic-gate 		return (0);
12957c478bd9Sstevel@tonic-gate 	else
12967c478bd9Sstevel@tonic-gate 		return (-1);
12977c478bd9Sstevel@tonic-gate }
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate static void
get_type(hpc_board_type_t boardtype,hpc_card_info_t cardinfo,char * buf)13007c478bd9Sstevel@tonic-gate get_type(hpc_board_type_t boardtype, hpc_card_info_t cardinfo, char *buf)
13017c478bd9Sstevel@tonic-gate {
1302*bd97c7ceSRobert Mustacchi 	size_t i;
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate 	DBG(1, ("class: %i\n", cardinfo.base_class));
13057c478bd9Sstevel@tonic-gate 	DBG(1, ("subclass: %i\n", cardinfo.sub_class));
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 	if (cardinfo.base_class == PCI_CLASS_NONE) {
13087c478bd9Sstevel@tonic-gate 		TPCT("unknown");
13097c478bd9Sstevel@tonic-gate 		return;
13107c478bd9Sstevel@tonic-gate 	}
13117c478bd9Sstevel@tonic-gate 
131209f67678Sanish 	for (i = 0; i < class_pci_items; i++) {
131309f67678Sanish 		if ((cardinfo.base_class == class_pci[i].base_class) &&
131409f67678Sanish 		    (cardinfo.sub_class == class_pci[i].sub_class) &&
131509f67678Sanish 		    (cardinfo.prog_class == class_pci[i].prog_class)) {
131609f67678Sanish 			TPCT(class_pci[i].short_desc);
131709f67678Sanish 			break;
13187c478bd9Sstevel@tonic-gate 		}
13197c478bd9Sstevel@tonic-gate 	}
13207c478bd9Sstevel@tonic-gate 
132109f67678Sanish 	if (i == class_pci_items)
132209f67678Sanish 		TPCT("unknown");
132309f67678Sanish 
13247c478bd9Sstevel@tonic-gate 	TPCT("/");
13257c478bd9Sstevel@tonic-gate 	switch (boardtype) {
13267c478bd9Sstevel@tonic-gate 	case HPC_BOARD_PCI_HOTPLUG:
13277c478bd9Sstevel@tonic-gate 	case HPC_BOARD_CPCI_NON_HS:
13287c478bd9Sstevel@tonic-gate 	case HPC_BOARD_CPCI_BASIC_HS:
13297c478bd9Sstevel@tonic-gate 	case HPC_BOARD_CPCI_FULL_HS:
13307c478bd9Sstevel@tonic-gate 	case HPC_BOARD_CPCI_HS:
13317c478bd9Sstevel@tonic-gate 		TPCT(board_strs[boardtype]);
13327c478bd9Sstevel@tonic-gate 		break;
13337c478bd9Sstevel@tonic-gate 	case HPC_BOARD_UNKNOWN:
13347c478bd9Sstevel@tonic-gate 	default:
13357c478bd9Sstevel@tonic-gate 		TPCT(board_strs[HPC_BOARD_UNKNOWN]);
13367c478bd9Sstevel@tonic-gate 	}
13377c478bd9Sstevel@tonic-gate }
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate /*
13407c478bd9Sstevel@tonic-gate  * call-back function for di_devlink_walk
13417c478bd9Sstevel@tonic-gate  * if the link lives in /dev/cfg copy its name
13427c478bd9Sstevel@tonic-gate  */
13437c478bd9Sstevel@tonic-gate static int
found_devlink(di_devlink_t link,void * ap_log_id)13447c478bd9Sstevel@tonic-gate found_devlink(di_devlink_t link, void *ap_log_id)
13457c478bd9Sstevel@tonic-gate {
13467c478bd9Sstevel@tonic-gate 	if (strncmp("/dev/cfg/", di_devlink_path(link), 9) == 0) {
13477c478bd9Sstevel@tonic-gate 		/* copy everything but /dev/cfg/ */
13487c478bd9Sstevel@tonic-gate 		(void) strcpy((char *)ap_log_id, di_devlink_path(link) + 9);
13497c478bd9Sstevel@tonic-gate 		DBG(1, ("found_devlink: %s\n", (char *)ap_log_id));
13507c478bd9Sstevel@tonic-gate 		return (DI_WALK_TERMINATE);
13517c478bd9Sstevel@tonic-gate 	}
13527c478bd9Sstevel@tonic-gate 	return (DI_WALK_CONTINUE);
13537c478bd9Sstevel@tonic-gate }
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate /*
13567c478bd9Sstevel@tonic-gate  * Walk throught the cached /dev link tree looking for links to the ap
13577c478bd9Sstevel@tonic-gate  * if none are found return an error
13587c478bd9Sstevel@tonic-gate  */
13597c478bd9Sstevel@tonic-gate static cfga_err_t
check_devlinks(char * ap_log_id,const char * ap_id)13607c478bd9Sstevel@tonic-gate check_devlinks(char *ap_log_id, const char *ap_id)
13617c478bd9Sstevel@tonic-gate {
13627c478bd9Sstevel@tonic-gate 	di_devlink_handle_t hdl;
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate 	DBG(1, ("check_devlinks: %s\n", ap_id));
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 	hdl = di_devlink_init(NULL, 0);
13677c478bd9Sstevel@tonic-gate 
13687c478bd9Sstevel@tonic-gate 	if (strncmp("/devices/", ap_id, 9) == 0) {
13697c478bd9Sstevel@tonic-gate 		/* ap_id is a valid minor_path with /devices prepended */
13707c478bd9Sstevel@tonic-gate 		(void) di_devlink_walk(hdl, NULL, ap_id + 8, DI_PRIMARY_LINK,
13717c478bd9Sstevel@tonic-gate 		    (void *)ap_log_id, found_devlink);
13727c478bd9Sstevel@tonic-gate 	} else {
13737c478bd9Sstevel@tonic-gate 		DBG(1, ("check_devlinks: invalid ap_id: %s\n", ap_id));
13747c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
13757c478bd9Sstevel@tonic-gate 	}
13767c478bd9Sstevel@tonic-gate 
13777c478bd9Sstevel@tonic-gate 	(void) di_devlink_fini(&hdl);
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate 	if (ap_log_id[0] != '\0')
13807c478bd9Sstevel@tonic-gate 		return (CFGA_OK);
13817c478bd9Sstevel@tonic-gate 	else
13827c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
13837c478bd9Sstevel@tonic-gate }
13847c478bd9Sstevel@tonic-gate 
13857c478bd9Sstevel@tonic-gate /*
13867c478bd9Sstevel@tonic-gate  * most of this is needed to compensate for
13877c478bd9Sstevel@tonic-gate  * differences between various platforms
13887c478bd9Sstevel@tonic-gate  */
13897c478bd9Sstevel@tonic-gate static cfga_err_t
fix_ap_name(char * ap_log_id,const char * ap_id,char * slot_name,char ** errstring)13907c478bd9Sstevel@tonic-gate fix_ap_name(char *ap_log_id, const char *ap_id, char *slot_name,
13917c478bd9Sstevel@tonic-gate     char **errstring)
13927c478bd9Sstevel@tonic-gate {
13937c478bd9Sstevel@tonic-gate 	char *buf;
13947c478bd9Sstevel@tonic-gate 	char *tmp;
13957c478bd9Sstevel@tonic-gate 	char *ptr;
13967c478bd9Sstevel@tonic-gate 
13977c478bd9Sstevel@tonic-gate 	di_node_t ap_node;
13987c478bd9Sstevel@tonic-gate 
13997c478bd9Sstevel@tonic-gate 	ap_log_id[0] = '\0';
14007c478bd9Sstevel@tonic-gate 
14017c478bd9Sstevel@tonic-gate 	if (check_devlinks(ap_log_id, ap_id) == CFGA_OK)
14027c478bd9Sstevel@tonic-gate 		return (CFGA_OK);
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", ap_id));
14057c478bd9Sstevel@tonic-gate 
14067c478bd9Sstevel@tonic-gate 	if ((buf = malloc(strlen(ap_id) + 1)) == NULL) {
14077c478bd9Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
14087c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
14097c478bd9Sstevel@tonic-gate 	}
14107c478bd9Sstevel@tonic-gate 	(void) strcpy(buf, ap_id);
14117c478bd9Sstevel@tonic-gate 	tmp = buf + sizeof ("/devices") - 1;
14127c478bd9Sstevel@tonic-gate 
14137c478bd9Sstevel@tonic-gate 	ptr = strchr(tmp, ':');
14147c478bd9Sstevel@tonic-gate 	ptr[0] = '\0';
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", tmp));
14177c478bd9Sstevel@tonic-gate 
14187c478bd9Sstevel@tonic-gate 	ap_node = di_init(tmp, DINFOMINOR);
14197c478bd9Sstevel@tonic-gate 	if (ap_node == DI_NODE_NIL) {
14207c478bd9Sstevel@tonic-gate 		cfga_err(errstring, "di_init ", 0);
14217c478bd9Sstevel@tonic-gate 		DBG(1, ("fix_ap_name: failed to snapshot node\n"));
14227c478bd9Sstevel@tonic-gate 		return (CFGA_ERROR);
14237c478bd9Sstevel@tonic-gate 	}
14247c478bd9Sstevel@tonic-gate 
14257c478bd9Sstevel@tonic-gate 	(void) snprintf(ap_log_id, strlen(ap_id) + 1, "%s%i:%s",
14267c478bd9Sstevel@tonic-gate 	    di_driver_name(ap_node), di_instance(ap_node), slot_name);
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate 	DBG(1, ("fix_ap_name: %s\n", ap_log_id));
14297c478bd9Sstevel@tonic-gate 
14307c478bd9Sstevel@tonic-gate 	di_fini(ap_node);
14317c478bd9Sstevel@tonic-gate 
14327c478bd9Sstevel@tonic-gate 	free(buf);
14337c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
14347c478bd9Sstevel@tonic-gate }
14357c478bd9Sstevel@tonic-gate 
14363c4226f9Spjha 
14373c4226f9Spjha static int
findlink_cb(di_devlink_t devlink,void * arg)14383c4226f9Spjha findlink_cb(di_devlink_t devlink, void *arg)
14393c4226f9Spjha {
14403c4226f9Spjha 	(*(char **)arg) = strdup(di_devlink_path(devlink));
14413c4226f9Spjha 
14423c4226f9Spjha 	return (DI_WALK_TERMINATE);
14433c4226f9Spjha }
14443c4226f9Spjha 
14453c4226f9Spjha /*
14463c4226f9Spjha  * returns an allocated string containing the full path to the devlink for
14473c4226f9Spjha  * <ap_phys_id> in the devlink database; we expect only one devlink per
14483c4226f9Spjha  * <ap_phys_id> so we return the first encountered
14493c4226f9Spjha  */
14503c4226f9Spjha static char *
findlink(char * ap_phys_id)14513c4226f9Spjha findlink(char *ap_phys_id)
14523c4226f9Spjha {
14533c4226f9Spjha 	di_devlink_handle_t hdl;
14543c4226f9Spjha 	char *path = NULL;
14553c4226f9Spjha 
14563c4226f9Spjha 	hdl = di_devlink_init(NULL, 0);
14573c4226f9Spjha 
14583c4226f9Spjha 	if (strncmp("/devices/", ap_phys_id, 9) == 0)
14593c4226f9Spjha 		ap_phys_id += 8;
14603c4226f9Spjha 
14613c4226f9Spjha 	(void) di_devlink_walk(hdl, "^cfg/.+$", ap_phys_id, DI_PRIMARY_LINK,
14623c4226f9Spjha 	    (void *)&path, findlink_cb);
14633c4226f9Spjha 
14643c4226f9Spjha 	(void) di_devlink_fini(&hdl);
14653c4226f9Spjha 	return (path);
14663c4226f9Spjha }
14673c4226f9Spjha 
14683c4226f9Spjha 
14693c4226f9Spjha /*
14703c4226f9Spjha  * returns CFGA_OK if it can succesfully retrieve the devlink info associated
14713c4226f9Spjha  * with devlink for <ap_phys_id> which will be returned through <ap_info>
14723c4226f9Spjha  */
14733c4226f9Spjha cfga_err_t
get_dli(char * dlpath,char * ap_info,int ap_info_sz)14743c4226f9Spjha get_dli(char *dlpath, char *ap_info, int ap_info_sz)
14753c4226f9Spjha {
14763c4226f9Spjha 	int fd;
14773c4226f9Spjha 
14783c4226f9Spjha 	fd = di_dli_openr(dlpath);
14793c4226f9Spjha 	if (fd < 0)
14803c4226f9Spjha 		return (CFGA_ERROR);
14813c4226f9Spjha 
14823c4226f9Spjha 	(void) read(fd, ap_info, ap_info_sz);
14833c4226f9Spjha 	ap_info[ap_info_sz - 1] = '\0';
14843c4226f9Spjha 
14853c4226f9Spjha 	di_dli_close(fd);
14863c4226f9Spjha 	return (CFGA_OK);
14873c4226f9Spjha }
14883c4226f9Spjha 
14893c4226f9Spjha 
14907c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14917c478bd9Sstevel@tonic-gate cfga_err_t
cfga_list_ext(const char * ap_id,cfga_list_data_t ** cs,int * nlist,const char * options,const char * listopts,char ** errstring,cfga_flags_t flags)14927c478bd9Sstevel@tonic-gate cfga_list_ext(const char *ap_id, cfga_list_data_t **cs,
14937c478bd9Sstevel@tonic-gate     int *nlist, const char *options, const char *listopts, char **errstring,
14947c478bd9Sstevel@tonic-gate     cfga_flags_t flags)
14957c478bd9Sstevel@tonic-gate {
14967c478bd9Sstevel@tonic-gate 	devctl_hdl_t		dcp;
14977c478bd9Sstevel@tonic-gate 	struct hpc_control_data	iocdata;
14987c478bd9Sstevel@tonic-gate 	devctl_ap_state_t	state;
14997c478bd9Sstevel@tonic-gate 	hpc_board_type_t	boardtype;
15007c478bd9Sstevel@tonic-gate 	hpc_card_info_t		cardinfo;
15017c478bd9Sstevel@tonic-gate 	hpc_slot_info_t		slot_info;
15027c478bd9Sstevel@tonic-gate 	struct	searcharg	slotname_arg;
15037c478bd9Sstevel@tonic-gate 	int			fd;
15047c478bd9Sstevel@tonic-gate 	int			rv = CFGA_OK;
15053c4226f9Spjha 	char			*dlpath = NULL;
15067c478bd9Sstevel@tonic-gate 
15077c478bd9Sstevel@tonic-gate 	if ((rv = check_options(options)) != CFGA_OK) {
15087c478bd9Sstevel@tonic-gate 		return (rv);
15097c478bd9Sstevel@tonic-gate 	}
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate 	if (errstring != NULL)
15127c478bd9Sstevel@tonic-gate 		*errstring = NULL;
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate 	(void) memset(&slot_info, 0, sizeof (hpc_slot_info_t));
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_list_ext:(%s)\n", ap_id));
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate 	if (cs == NULL || nlist == NULL) {
15197c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15207c478bd9Sstevel@tonic-gate 		return (rv);
15217c478bd9Sstevel@tonic-gate 	}
15227c478bd9Sstevel@tonic-gate 
15237c478bd9Sstevel@tonic-gate 	*nlist = 1;
15247c478bd9Sstevel@tonic-gate 
15257c478bd9Sstevel@tonic-gate 	if ((*cs = malloc(sizeof (cfga_list_data_t))) == NULL) {
15267c478bd9Sstevel@tonic-gate 		cfga_err(errstring, "malloc ", 0);
15277c478bd9Sstevel@tonic-gate 		DBG(1, ("malloc failed\n"));
15287c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15297c478bd9Sstevel@tonic-gate 		return (rv);
15307c478bd9Sstevel@tonic-gate 	}
15313c4226f9Spjha 	(void) memset(*cs, 0, sizeof (cfga_list_data_t));
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate 	if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
15347c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, 0);
15357c478bd9Sstevel@tonic-gate 		DBG(2, ("cfga_list_ext::(devctl_ap_acquire())\n"));
15367c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15377c478bd9Sstevel@tonic-gate 		return (rv);
15387c478bd9Sstevel@tonic-gate 	}
15397c478bd9Sstevel@tonic-gate 
15407c478bd9Sstevel@tonic-gate 	if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
15417c478bd9Sstevel@tonic-gate 		cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
15427c478bd9Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15437c478bd9Sstevel@tonic-gate 		DBG(2, ("cfga_list_ext::(devctl_ap_getstate())\n"));
15447c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15457c478bd9Sstevel@tonic-gate 		return (rv);
15467c478bd9Sstevel@tonic-gate 	}
15477c478bd9Sstevel@tonic-gate 
15487c478bd9Sstevel@tonic-gate 	switch (state.ap_rstate) {
15497c478bd9Sstevel@tonic-gate 		case AP_RSTATE_EMPTY:
15507c478bd9Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_EMPTY;
15517c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_EMPTY\n"));
15527c478bd9Sstevel@tonic-gate 			break;
15537c478bd9Sstevel@tonic-gate 		case AP_RSTATE_DISCONNECTED:
15547c478bd9Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_DISCONNECTED;
15557c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_DISCONNECTED\n"));
15567c478bd9Sstevel@tonic-gate 			break;
15577c478bd9Sstevel@tonic-gate 		case AP_RSTATE_CONNECTED:
15587c478bd9Sstevel@tonic-gate 			(*cs)->ap_r_state = CFGA_STAT_CONNECTED;
15597c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_rstate = CFGA_STAT_CONNECTED\n"));
15607c478bd9Sstevel@tonic-gate 			break;
15617c478bd9Sstevel@tonic-gate 	default:
15627c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
15637c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15647c478bd9Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15657c478bd9Sstevel@tonic-gate 		return (rv);
15667c478bd9Sstevel@tonic-gate 	}
15677c478bd9Sstevel@tonic-gate 
15687c478bd9Sstevel@tonic-gate 	switch (state.ap_ostate) {
15697c478bd9Sstevel@tonic-gate 		case AP_OSTATE_CONFIGURED:
15707c478bd9Sstevel@tonic-gate 			(*cs)->ap_o_state = CFGA_STAT_CONFIGURED;
15717c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_ostate = CFGA_STAT_CONFIGURED\n"));
15727c478bd9Sstevel@tonic-gate 			break;
15737c478bd9Sstevel@tonic-gate 		case AP_OSTATE_UNCONFIGURED:
15747c478bd9Sstevel@tonic-gate 			(*cs)->ap_o_state = CFGA_STAT_UNCONFIGURED;
15757c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_ostate = CFGA_STAT_UNCONFIGURED\n"));
15767c478bd9Sstevel@tonic-gate 			break;
15777c478bd9Sstevel@tonic-gate 	default:
15787c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
15797c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
15807c478bd9Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
15817c478bd9Sstevel@tonic-gate 		return (rv);
15827c478bd9Sstevel@tonic-gate 	}
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate 	switch (state.ap_condition) {
15857c478bd9Sstevel@tonic-gate 		case AP_COND_OK:
15867c478bd9Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_OK;
15877c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_OK\n"));
15887c478bd9Sstevel@tonic-gate 			break;
15897c478bd9Sstevel@tonic-gate 		case AP_COND_FAILING:
15907c478bd9Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_FAILING;
15917c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_FAILING\n"));
15927c478bd9Sstevel@tonic-gate 			break;
15937c478bd9Sstevel@tonic-gate 		case AP_COND_FAILED:
15947c478bd9Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_FAILED;
15957c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_FAILED\n"));
15967c478bd9Sstevel@tonic-gate 			break;
15977c478bd9Sstevel@tonic-gate 		case AP_COND_UNUSABLE:
15987c478bd9Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_UNUSABLE;
15997c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_UNUSABLE\n"));
16007c478bd9Sstevel@tonic-gate 			break;
16017c478bd9Sstevel@tonic-gate 		case AP_COND_UNKNOWN:
16027c478bd9Sstevel@tonic-gate 			(*cs)->ap_cond = CFGA_COND_UNKNOWN;
16037c478bd9Sstevel@tonic-gate 			DBG(2, ("ap_cond = CFGA_COND_UNKNOW\n"));
16047c478bd9Sstevel@tonic-gate 			break;
16057c478bd9Sstevel@tonic-gate 	default:
16067c478bd9Sstevel@tonic-gate 		cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
16077c478bd9Sstevel@tonic-gate 		rv = CFGA_ERROR;
16087c478bd9Sstevel@tonic-gate 		devctl_release((devctl_hdl_t)dcp);
16097c478bd9Sstevel@tonic-gate 		return (rv);
16107c478bd9Sstevel@tonic-gate 	}
16117c478bd9Sstevel@tonic-gate 	(*cs)->ap_busy = (int)state.ap_in_transition;
16127c478bd9Sstevel@tonic-gate 
16137c478bd9Sstevel@tonic-gate 	devctl_release((devctl_hdl_t)dcp);
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate 	if ((fd = open(ap_id, O_RDWR)) == -1) {
16167c478bd9Sstevel@tonic-gate 		cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
16177c478bd9Sstevel@tonic-gate 		(*cs)->ap_status_time = 0;
16187c478bd9Sstevel@tonic-gate 		boardtype = HPC_BOARD_UNKNOWN;
16197c478bd9Sstevel@tonic-gate 		cardinfo.base_class = PCI_CLASS_NONE;
16207c478bd9Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
16217c478bd9Sstevel@tonic-gate 		DBG(2, ("open on %s failed\n", ap_id));
16227c478bd9Sstevel@tonic-gate 		goto cont;
16237c478bd9Sstevel@tonic-gate 	}
16247c478bd9Sstevel@tonic-gate 	DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
16257c478bd9Sstevel@tonic-gate 
16267c478bd9Sstevel@tonic-gate 	(*cs)->ap_status_time = state.ap_last_change;
16277c478bd9Sstevel@tonic-gate 
16287c478bd9Sstevel@tonic-gate 	/* need board type and a way to get to hpc_slot_info */
16297c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_BOARD_TYPE,
16307c478bd9Sstevel@tonic-gate 	    (void *)&boardtype);
16317c478bd9Sstevel@tonic-gate 
16327c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
16337c478bd9Sstevel@tonic-gate 		boardtype = HPC_BOARD_UNKNOWN;
16347c478bd9Sstevel@tonic-gate 	}
16357c478bd9Sstevel@tonic-gate 	DBG(1, ("ioctl boardtype\n"));
16367c478bd9Sstevel@tonic-gate 
16377c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
16387c478bd9Sstevel@tonic-gate 	    (void *)&slot_info);
16397c478bd9Sstevel@tonic-gate 
16407c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
16417c478bd9Sstevel@tonic-gate 		get_logical_name(ap_id, slot_info.pci_slot_name, 0);
16427c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl failed slotinfo: %s\n",
16437c478bd9Sstevel@tonic-gate 		    slot_info.pci_slot_name));
16447c478bd9Sstevel@tonic-gate 	} else {
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate 		/*
16477c478bd9Sstevel@tonic-gate 		 * the driver will report back things like hpc0_slot0
16487c478bd9Sstevel@tonic-gate 		 * this needs to be changed to things like pci1:hpc0_slot0
16497c478bd9Sstevel@tonic-gate 		 */
16507c478bd9Sstevel@tonic-gate 		rv = fix_ap_name((*cs)->ap_log_id,
16517c478bd9Sstevel@tonic-gate 		    ap_id, slot_info.pci_slot_name, errstring);
16527c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl slotinfo: %s\n", (*cs)->ap_log_id));
16537c478bd9Sstevel@tonic-gate 	}
16547c478bd9Sstevel@tonic-gate 
16557c478bd9Sstevel@tonic-gate 	build_control_data(&iocdata, HPC_CTRL_GET_CARD_INFO,
16567c478bd9Sstevel@tonic-gate 	    (void *)&cardinfo);
16577c478bd9Sstevel@tonic-gate 
16587c478bd9Sstevel@tonic-gate 	if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
16597c478bd9Sstevel@tonic-gate 		DBG(1, ("ioctl failed\n"));
16607c478bd9Sstevel@tonic-gate 		cardinfo.base_class = PCI_CLASS_NONE;
16617c478bd9Sstevel@tonic-gate 	}
16627c478bd9Sstevel@tonic-gate 
16637c478bd9Sstevel@tonic-gate 	DBG(1, ("ioctl cardinfo: %d\n", cardinfo.base_class));
16647c478bd9Sstevel@tonic-gate 	DBG(1, ("ioctl subclass: %d\n", cardinfo.sub_class));
16657c478bd9Sstevel@tonic-gate 	DBG(1, ("ioctl headertype: %d\n", cardinfo.header_type));
16667c478bd9Sstevel@tonic-gate 
16677c478bd9Sstevel@tonic-gate 	(void) close(fd);
16687c478bd9Sstevel@tonic-gate 
16697c478bd9Sstevel@tonic-gate cont:
16707c478bd9Sstevel@tonic-gate 	(void) strcpy((*cs)->ap_phys_id, ap_id);    /* physical path of AP */
16713c4226f9Spjha 
16723c4226f9Spjha 	dlpath = findlink((*cs)->ap_phys_id);
16733c4226f9Spjha 	if (dlpath != NULL) {
16743c4226f9Spjha 		if (get_dli(dlpath, (*cs)->ap_info,
16753c4226f9Spjha 		    sizeof ((*cs)->ap_info)) != CFGA_OK)
16763c4226f9Spjha 			(*cs)->ap_info[0] = '\0';
16773c4226f9Spjha 		free(dlpath);
16783c4226f9Spjha 	}
16793c4226f9Spjha 
16807c478bd9Sstevel@tonic-gate 	if ((*cs)->ap_log_id[0] == '\0')
16817c478bd9Sstevel@tonic-gate 		(void) strcpy((*cs)->ap_log_id, slot_info.pci_slot_name);
16827c478bd9Sstevel@tonic-gate 
16833c4226f9Spjha 	if ((*cs)->ap_info[0] == '\0') {
16843c4226f9Spjha 		/* slot_names of bus node  */
1685014ec826SToomas Soome 		memset(&slotname_arg, 0, sizeof (slotname_arg));
16863c4226f9Spjha 		if (find_physical_slot_names(ap_id, &slotname_arg) != -1)
16873c4226f9Spjha 			(void) strcpy((*cs)->ap_info,
16883c4226f9Spjha 			    slotname_arg.slotnames[slotname_arg.minor]);
16893c4226f9Spjha 	}
16907c478bd9Sstevel@tonic-gate 
16917c478bd9Sstevel@tonic-gate 	/* class_code/subclass/boardtype */
16927c478bd9Sstevel@tonic-gate 	get_type(boardtype, cardinfo, (*cs)->ap_type);
16937c478bd9Sstevel@tonic-gate 
16947c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_list_ext return success\n"));
16957c478bd9Sstevel@tonic-gate 	rv = CFGA_OK;
16967c478bd9Sstevel@tonic-gate 
16977c478bd9Sstevel@tonic-gate 	return (rv);
16987c478bd9Sstevel@tonic-gate }
16997c478bd9Sstevel@tonic-gate 
17007c478bd9Sstevel@tonic-gate /*
17017c478bd9Sstevel@tonic-gate  * This routine prints a single line of help message
17027c478bd9Sstevel@tonic-gate  */
17037c478bd9Sstevel@tonic-gate static void
cfga_msg(struct cfga_msg * msgp,const char * str)17047c478bd9Sstevel@tonic-gate cfga_msg(struct cfga_msg *msgp, const char *str)
17057c478bd9Sstevel@tonic-gate {
17067c478bd9Sstevel@tonic-gate 	DBG(2, ("<%s>", str));
17077c478bd9Sstevel@tonic-gate 
17087c478bd9Sstevel@tonic-gate 	if (msgp == NULL || msgp->message_routine == NULL)
17097c478bd9Sstevel@tonic-gate 		return;
17107c478bd9Sstevel@tonic-gate 
17117c478bd9Sstevel@tonic-gate 	(*msgp->message_routine)(msgp->appdata_ptr, str);
17127c478bd9Sstevel@tonic-gate 	(*msgp->message_routine)(msgp->appdata_ptr, "\n");
17137c478bd9Sstevel@tonic-gate }
17147c478bd9Sstevel@tonic-gate 
17157c478bd9Sstevel@tonic-gate static cfga_err_t
check_options(const char * options)17167c478bd9Sstevel@tonic-gate check_options(const char *options)
17177c478bd9Sstevel@tonic-gate {
17187c478bd9Sstevel@tonic-gate 	struct cfga_msg *msgp = NULL;
17197c478bd9Sstevel@tonic-gate 
17207c478bd9Sstevel@tonic-gate 	if (options) {
17217c478bd9Sstevel@tonic-gate 		cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
17227c478bd9Sstevel@tonic-gate 		cfga_msg(msgp, options);
17237c478bd9Sstevel@tonic-gate 		return (CFGA_INVAL);
17247c478bd9Sstevel@tonic-gate 	}
17257c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
17267c478bd9Sstevel@tonic-gate }
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17297c478bd9Sstevel@tonic-gate cfga_err_t
cfga_help(struct cfga_msg * msgp,const char * options,cfga_flags_t flags)17307c478bd9Sstevel@tonic-gate cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
17317c478bd9Sstevel@tonic-gate {
17327c478bd9Sstevel@tonic-gate 	if (options) {
17337c478bd9Sstevel@tonic-gate 		cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
17347c478bd9Sstevel@tonic-gate 		cfga_msg(msgp, options);
17357c478bd9Sstevel@tonic-gate 	}
17367c478bd9Sstevel@tonic-gate 	DBG(1, ("cfga_help\n"));
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_HEADER]));
17397c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_CONFIG]);
17407c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_ENABLE_SLOT]);
17417c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_DISABLE_SLOT]);
17427c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_ENABLE_AUTOCONF]);
17437c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_DISABLE_AUTOCONF]);
17447c478bd9Sstevel@tonic-gate 	cfga_msg(msgp, cfga_strs[HELP_LED_CNTRL]);
17457c478bd9Sstevel@tonic-gate 	return (CFGA_OK);
17467c478bd9Sstevel@tonic-gate }
17477c478bd9Sstevel@tonic-gate 
17487c478bd9Sstevel@tonic-gate /*
17497c478bd9Sstevel@tonic-gate  * cfga_err() accepts a variable number of message IDs and constructs
17507c478bd9Sstevel@tonic-gate  * a corresponding error string which is returned via the errstring argument.
17517c478bd9Sstevel@tonic-gate  * cfga_err() calls gettext() to internationalize proper messages.
17527c478bd9Sstevel@tonic-gate  */
17537c478bd9Sstevel@tonic-gate static void
cfga_err(char ** errstring,...)17547c478bd9Sstevel@tonic-gate cfga_err(char **errstring, ...)
17557c478bd9Sstevel@tonic-gate {
17567c478bd9Sstevel@tonic-gate 	int a;
17577c478bd9Sstevel@tonic-gate 	int i;
17587c478bd9Sstevel@tonic-gate 	int n;
17597c478bd9Sstevel@tonic-gate 	int len;
17607c478bd9Sstevel@tonic-gate 	int flen;
17617c478bd9Sstevel@tonic-gate 	char *p;
17627c478bd9Sstevel@tonic-gate 	char *q;
17637c478bd9Sstevel@tonic-gate 	char *s[32];
17647c478bd9Sstevel@tonic-gate 	char *failed;
17657c478bd9Sstevel@tonic-gate 	va_list ap;
17667c478bd9Sstevel@tonic-gate 
17677c478bd9Sstevel@tonic-gate 	/*
17687c478bd9Sstevel@tonic-gate 	 * If errstring is null it means user in not interested in getting
17697c478bd9Sstevel@tonic-gate 	 * error status. So we don't do all the work
17707c478bd9Sstevel@tonic-gate 	 */
17717c478bd9Sstevel@tonic-gate 	if (errstring == NULL) {
17727c478bd9Sstevel@tonic-gate 		return;
17737c478bd9Sstevel@tonic-gate 	}
17747c478bd9Sstevel@tonic-gate 	va_start(ap, errstring);
17757c478bd9Sstevel@tonic-gate 
17767c478bd9Sstevel@tonic-gate 	failed = dgettext(TEXT_DOMAIN, cfga_strs[FAILED]);
17777c478bd9Sstevel@tonic-gate 	flen = strlen(failed);
17787c478bd9Sstevel@tonic-gate 
17797c478bd9Sstevel@tonic-gate 	for (n = len = 0; (a = va_arg(ap, int)) != 0; n++) {
17807c478bd9Sstevel@tonic-gate 		switch (a) {
17817c478bd9Sstevel@tonic-gate 		case CMD_GETSTAT:
17827c478bd9Sstevel@tonic-gate 		case CMD_LIST:
17837c478bd9Sstevel@tonic-gate 		case CMD_SLOT_CONNECT:
17847c478bd9Sstevel@tonic-gate 		case CMD_SLOT_DISCONNECT:
17857c478bd9Sstevel@tonic-gate 		case CMD_SLOT_CONFIGURE:
17867c478bd9Sstevel@tonic-gate 		case CMD_SLOT_UNCONFIGURE:
17877c478bd9Sstevel@tonic-gate 			p =  cfga_errstrs(a);
17887c478bd9Sstevel@tonic-gate 			len += (strlen(p) + flen);
17897c478bd9Sstevel@tonic-gate 			s[n] = p;
17907c478bd9Sstevel@tonic-gate 			s[++n] = cfga_strs[FAILED];
17917c478bd9Sstevel@tonic-gate 
17927c478bd9Sstevel@tonic-gate 			DBG(2, ("<%s>", p));
17937c478bd9Sstevel@tonic-gate 			DBG(2, (cfga_strs[FAILED]));
17947c478bd9Sstevel@tonic-gate 			break;
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 		case ERR_CMD_INVAL:
17977c478bd9Sstevel@tonic-gate 		case ERR_AP_INVAL:
17987c478bd9Sstevel@tonic-gate 		case ERR_OPT_INVAL:
17997c478bd9Sstevel@tonic-gate 		case ERR_AP_ERR:
18007c478bd9Sstevel@tonic-gate 			switch (a) {
18017c478bd9Sstevel@tonic-gate 			case ERR_CMD_INVAL:
18027c478bd9Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
18037c478bd9Sstevel@tonic-gate 				    cfga_errstrs[ERR_CMD_INVAL]);
18047c478bd9Sstevel@tonic-gate 				break;
18057c478bd9Sstevel@tonic-gate 			case ERR_AP_INVAL:
18067c478bd9Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
18077c478bd9Sstevel@tonic-gate 				    cfga_errstrs[ERR_AP_INVAL]);
18087c478bd9Sstevel@tonic-gate 				break;
18097c478bd9Sstevel@tonic-gate 			case ERR_OPT_INVAL:
18107c478bd9Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
18117c478bd9Sstevel@tonic-gate 				    cfga_errstrs[ERR_OPT_INVAL]);
18127c478bd9Sstevel@tonic-gate 				break;
18137c478bd9Sstevel@tonic-gate 			case ERR_AP_ERR:
18147c478bd9Sstevel@tonic-gate 				p = dgettext(TEXT_DOMAIN,
18157c478bd9Sstevel@tonic-gate 				    cfga_errstrs[ERR_AP_ERR]);
18167c478bd9Sstevel@tonic-gate 				break;
18177c478bd9Sstevel@tonic-gate 			}
18187c478bd9Sstevel@tonic-gate 
18197c478bd9Sstevel@tonic-gate 			if ((q = va_arg(ap, char *)) != NULL) {
18207c478bd9Sstevel@tonic-gate 				len += (strlen(p) + strlen(q));
18217c478bd9Sstevel@tonic-gate 				s[n] = p;
18227c478bd9Sstevel@tonic-gate 				s[++n] = q;
18237c478bd9Sstevel@tonic-gate 				DBG(2, ("<%s>", p));
18247c478bd9Sstevel@tonic-gate 				DBG(2, ("<%s>", q));
18257c478bd9Sstevel@tonic-gate 				break;
18267c478bd9Sstevel@tonic-gate 			} else {
18277c478bd9Sstevel@tonic-gate 				len += strlen(p);
18287c478bd9Sstevel@tonic-gate 				s[n] = p;
18297c478bd9Sstevel@tonic-gate 
18307c478bd9Sstevel@tonic-gate 			}
18317c478bd9Sstevel@tonic-gate 			DBG(2, ("<%s>", p));
18327c478bd9Sstevel@tonic-gate 			break;
18337c478bd9Sstevel@tonic-gate 
18347c478bd9Sstevel@tonic-gate 		default:
18357c478bd9Sstevel@tonic-gate 			n--;
18367c478bd9Sstevel@tonic-gate 			break;
18377c478bd9Sstevel@tonic-gate 		}
18387c478bd9Sstevel@tonic-gate 	}
18397c478bd9Sstevel@tonic-gate 
18407c478bd9Sstevel@tonic-gate 	DBG(2, ("\n"));
18417c478bd9Sstevel@tonic-gate 	va_end(ap);
18427c478bd9Sstevel@tonic-gate 
18437c478bd9Sstevel@tonic-gate 	if ((p = calloc(len + 1, 1)) == NULL)
18447c478bd9Sstevel@tonic-gate 		return;
18457c478bd9Sstevel@tonic-gate 
18467c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
18477c478bd9Sstevel@tonic-gate 		(void) strlcat(p, s[i], len + 1);
18487c478bd9Sstevel@tonic-gate 		DBG(2, ("i:%d, %s\n", i, s[i]));
18497c478bd9Sstevel@tonic-gate 	}
18507c478bd9Sstevel@tonic-gate 
18517c478bd9Sstevel@tonic-gate 	*errstring = p;
18527c478bd9Sstevel@tonic-gate #ifdef	DEBUG
18537c478bd9Sstevel@tonic-gate 	printf("%s\n", *errstring);
18547c478bd9Sstevel@tonic-gate 	free(*errstring);
18557c478bd9Sstevel@tonic-gate #endif
18567c478bd9Sstevel@tonic-gate }
18577c478bd9Sstevel@tonic-gate 
18587c478bd9Sstevel@tonic-gate /*
18597c478bd9Sstevel@tonic-gate  * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm
18607c478bd9Sstevel@tonic-gate  */
1861