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