1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Plugin Library for PCI Hot-Plug Controller 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stddef.h> 34*0Sstevel@tonic-gate #include <locale.h> 35*0Sstevel@tonic-gate #include <ctype.h> 36*0Sstevel@tonic-gate #include <stdio.h> 37*0Sstevel@tonic-gate #include <stdlib.h> 38*0Sstevel@tonic-gate #include <string.h> 39*0Sstevel@tonic-gate #include <fcntl.h> 40*0Sstevel@tonic-gate #include <unistd.h> 41*0Sstevel@tonic-gate #include <errno.h> 42*0Sstevel@tonic-gate #include <locale.h> 43*0Sstevel@tonic-gate #include <langinfo.h> 44*0Sstevel@tonic-gate #include <time.h> 45*0Sstevel@tonic-gate #include <sys/param.h> 46*0Sstevel@tonic-gate #include <stdarg.h> 47*0Sstevel@tonic-gate #include <libdevinfo.h> 48*0Sstevel@tonic-gate #include <libdevice.h> 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate #define CFGA_PLUGIN_LIB 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate #include <config_admin.h> 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate #include <sys/types.h> 55*0Sstevel@tonic-gate #include <sys/stat.h> 56*0Sstevel@tonic-gate #include <sys/ioctl.h> 57*0Sstevel@tonic-gate #include <sys/dditypes.h> 58*0Sstevel@tonic-gate #include <sys/devctl.h> 59*0Sstevel@tonic-gate #include <sys/modctl.h> 60*0Sstevel@tonic-gate #include <sys/hotplug/hpctrl.h> 61*0Sstevel@tonic-gate #include <sys/pci.h> 62*0Sstevel@tonic-gate #include <libintl.h> 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate #include <dirent.h> 65*0Sstevel@tonic-gate #include <limits.h> 66*0Sstevel@tonic-gate #include <sys/mkdev.h> 67*0Sstevel@tonic-gate #include <librcm.h> 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate /* 70*0Sstevel@tonic-gate * Set the version number 71*0Sstevel@tonic-gate */ 72*0Sstevel@tonic-gate int cfga_version = CFGA_HSL_V2; 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate #ifdef DEBUG 75*0Sstevel@tonic-gate #define PCIHP_DBG 1 76*0Sstevel@tonic-gate #endif 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 79*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 80*0Sstevel@tonic-gate #endif 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate /* 83*0Sstevel@tonic-gate * DEBUGING LEVEL 84*0Sstevel@tonic-gate * 85*0Sstevel@tonic-gate * External routines: 1 - 2 86*0Sstevel@tonic-gate * Internal routines: 3 - 4 87*0Sstevel@tonic-gate */ 88*0Sstevel@tonic-gate #ifdef PCIHP_DBG 89*0Sstevel@tonic-gate int pcihp_debug = 1; 90*0Sstevel@tonic-gate #define DBG(level, args) \ 91*0Sstevel@tonic-gate { if (pcihp_debug >= (level)) printf args; } 92*0Sstevel@tonic-gate #define DBG_F(level, args) \ 93*0Sstevel@tonic-gate { if (pcihp_debug >= (level)) fprintf args; } 94*0Sstevel@tonic-gate #else 95*0Sstevel@tonic-gate #define DBG(level, args) /* nothing */ 96*0Sstevel@tonic-gate #define DBG_F(level, args) /* nothing */ 97*0Sstevel@tonic-gate #endif 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate #define CMD_ACQUIRE 0 100*0Sstevel@tonic-gate #define CMD_GETSTAT 1 101*0Sstevel@tonic-gate #define CMD_LIST 2 102*0Sstevel@tonic-gate #define CMD_SLOT_CONNECT 3 103*0Sstevel@tonic-gate #define CMD_SLOT_DISCONNECT 4 104*0Sstevel@tonic-gate #define CMD_SLOT_CONFIGURE 5 105*0Sstevel@tonic-gate #define CMD_SLOT_UNCONFIGURE 6 106*0Sstevel@tonic-gate #define CMD_SLOT_INSERT 7 107*0Sstevel@tonic-gate #define CMD_SLOT_REMOVE 8 108*0Sstevel@tonic-gate #define CMD_OPEN 9 109*0Sstevel@tonic-gate #define CMD_FSTAT 10 110*0Sstevel@tonic-gate #define ERR_CMD_INVAL 11 111*0Sstevel@tonic-gate #define ERR_AP_INVAL 12 112*0Sstevel@tonic-gate #define ERR_AP_ERR 13 113*0Sstevel@tonic-gate #define ERR_OPT_INVAL 14 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate static char * 116*0Sstevel@tonic-gate cfga_errstrs[] = { 117*0Sstevel@tonic-gate /* n */ "acquire ", 118*0Sstevel@tonic-gate /* n */ "get-status ", 119*0Sstevel@tonic-gate /* n */ "list ", 120*0Sstevel@tonic-gate /* n */ "connect ", 121*0Sstevel@tonic-gate /* n */ "disconnect ", 122*0Sstevel@tonic-gate /* n */ "configure ", 123*0Sstevel@tonic-gate /* n */ "unconfigure ", 124*0Sstevel@tonic-gate /* n */ "insert ", 125*0Sstevel@tonic-gate /* n */ "remove ", 126*0Sstevel@tonic-gate /* n */ "open ", 127*0Sstevel@tonic-gate /* n */ "fstat ", 128*0Sstevel@tonic-gate /* y */ "invalid command ", 129*0Sstevel@tonic-gate /* y */ "invalid attachment point ", 130*0Sstevel@tonic-gate /* y */ "invalid transition ", 131*0Sstevel@tonic-gate /* y */ "invalid option ", 132*0Sstevel@tonic-gate NULL 133*0Sstevel@tonic-gate }; 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate #define HELP_HEADER 1 136*0Sstevel@tonic-gate #define HELP_CONFIG 2 137*0Sstevel@tonic-gate #define HELP_ENABLE_SLOT 3 138*0Sstevel@tonic-gate #define HELP_DISABLE_SLOT 4 139*0Sstevel@tonic-gate #define HELP_ENABLE_AUTOCONF 5 140*0Sstevel@tonic-gate #define HELP_DISABLE_AUTOCONF 6 141*0Sstevel@tonic-gate #define HELP_LED_CNTRL 7 142*0Sstevel@tonic-gate #define HELP_UNKNOWN 8 143*0Sstevel@tonic-gate #define SUCCESS 9 144*0Sstevel@tonic-gate #define FAILED 10 145*0Sstevel@tonic-gate #define UNKNOWN 11 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate #define MAXLINE 256 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate /* for type string assembly in get_type() */ 150*0Sstevel@tonic-gate #define TPCT(s) (void) strlcat(buf, (s), CFGA_TYPE_LEN) 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate extern int errno; 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate static void cfga_err(char **errstring, ...); 155*0Sstevel@tonic-gate static cfga_err_t fix_ap_name(char *ap_log_id, const char *ap_id, 156*0Sstevel@tonic-gate char *slot_name, char **errstring); 157*0Sstevel@tonic-gate static void build_control_data(struct hpc_control_data *iocdata, uint_t cmd, 158*0Sstevel@tonic-gate void *retdata); 159*0Sstevel@tonic-gate static cfga_err_t check_options(const char *options); 160*0Sstevel@tonic-gate static void cfga_msg(struct cfga_msg *msgp, const char *str); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate static char * 163*0Sstevel@tonic-gate cfga_strs[] = { 164*0Sstevel@tonic-gate NULL, 165*0Sstevel@tonic-gate "\nPCI hotplug specific commands:", 166*0Sstevel@tonic-gate "\t-c [connect|disconnect|configure|unconfigure|insert|remove] " 167*0Sstevel@tonic-gate "ap_id [ap_id...]", 168*0Sstevel@tonic-gate "\t-x enable_slot ap_id [ap_id...]", 169*0Sstevel@tonic-gate "\t-x disable_slot ap_id [ap_id...]", 170*0Sstevel@tonic-gate "\t-x enable_autoconfig ap_id [ap_id...]", 171*0Sstevel@tonic-gate "\t-x disable_autoconfig ap_id [ap_id...]", 172*0Sstevel@tonic-gate "\t-x led[=[fault|power|active|attn],mode=[on|off|blink]] ap_id [ap_id...]", 173*0Sstevel@tonic-gate "\tunknown command or option: ", 174*0Sstevel@tonic-gate "success ", 175*0Sstevel@tonic-gate "failed ", 176*0Sstevel@tonic-gate "unknown", 177*0Sstevel@tonic-gate NULL 178*0Sstevel@tonic-gate }; 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate #define MAX_FORMAT 80 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate /* 183*0Sstevel@tonic-gate * PCI CLASS CODE/SUBCLASS CODE 184*0Sstevel@tonic-gate */ 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate /* 188*0Sstevel@tonic-gate * when adding subclasses, update this to the max number of strings 189*0Sstevel@tonic-gate * and pad the rest of them out to that length with "unknown" 190*0Sstevel@tonic-gate * this type string may not exceed 7 characters since it, the / delimiter 191*0Sstevel@tonic-gate * and the board capabilities must all fit into CFGA_TYPE_LEN 192*0Sstevel@tonic-gate */ 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate #define PCISO_MAX_SUBCLASS 9 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate static char * 197*0Sstevel@tonic-gate pci_masstrg [] = { 198*0Sstevel@tonic-gate /* n */ "scsi", 199*0Sstevel@tonic-gate /* n */ "ide", 200*0Sstevel@tonic-gate /* n */ "flpydis", 201*0Sstevel@tonic-gate /* n */ "ipi", 202*0Sstevel@tonic-gate /* n */ "raid", 203*0Sstevel@tonic-gate /* n */ "unknown", 204*0Sstevel@tonic-gate /* n */ "unknown", 205*0Sstevel@tonic-gate /* n */ "unknown", 206*0Sstevel@tonic-gate /* n */ "unknown", 207*0Sstevel@tonic-gate /* n */ "unknown", 208*0Sstevel@tonic-gate /* n */ NULL 209*0Sstevel@tonic-gate }; 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate static char * 212*0Sstevel@tonic-gate pci_network [] = { 213*0Sstevel@tonic-gate /* n */ "etherne", 214*0Sstevel@tonic-gate /* n */ "tokenrg", 215*0Sstevel@tonic-gate /* n */ "fddi", 216*0Sstevel@tonic-gate /* n */ "atm", 217*0Sstevel@tonic-gate /* n */ "isdn", 218*0Sstevel@tonic-gate /* n */ "unknown", 219*0Sstevel@tonic-gate /* n */ "mcd", 220*0Sstevel@tonic-gate /* n */ "unknown", 221*0Sstevel@tonic-gate /* n */ "unknown", 222*0Sstevel@tonic-gate /* n */ "unknown", 223*0Sstevel@tonic-gate /* n */ NULL 224*0Sstevel@tonic-gate }; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate static char * 227*0Sstevel@tonic-gate pci_display [] = { 228*0Sstevel@tonic-gate /* n */ "vgs8514", 229*0Sstevel@tonic-gate /* n */ "xga", 230*0Sstevel@tonic-gate /* n */ "3d", 231*0Sstevel@tonic-gate /* n */ "unknown", 232*0Sstevel@tonic-gate /* n */ "unknown", 233*0Sstevel@tonic-gate /* n */ "unknown", 234*0Sstevel@tonic-gate /* n */ "unknown", 235*0Sstevel@tonic-gate /* n */ "unknown", 236*0Sstevel@tonic-gate /* n */ "unknown", 237*0Sstevel@tonic-gate /* n */ "unknown", 238*0Sstevel@tonic-gate /* n */ NULL 239*0Sstevel@tonic-gate }; 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate static char * 242*0Sstevel@tonic-gate pci_multimd [] = { 243*0Sstevel@tonic-gate /* n */ "video", 244*0Sstevel@tonic-gate /* n */ "audio", 245*0Sstevel@tonic-gate /* n */ "teleph", 246*0Sstevel@tonic-gate /* n */ "unknown", 247*0Sstevel@tonic-gate /* n */ "unknown", 248*0Sstevel@tonic-gate /* n */ "unknown", 249*0Sstevel@tonic-gate /* n */ "unknown", 250*0Sstevel@tonic-gate /* n */ "unknown", 251*0Sstevel@tonic-gate /* n */ "unknown", 252*0Sstevel@tonic-gate /* n */ "unknown", 253*0Sstevel@tonic-gate /* n */ NULL 254*0Sstevel@tonic-gate }; 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate static char * 257*0Sstevel@tonic-gate pci_memory [] = { 258*0Sstevel@tonic-gate /* n */ "ram", 259*0Sstevel@tonic-gate /* n */ "flash", 260*0Sstevel@tonic-gate /* n */ "unknown", 261*0Sstevel@tonic-gate /* n */ "unknown", 262*0Sstevel@tonic-gate /* n */ "unknown", 263*0Sstevel@tonic-gate /* n */ "unknown", 264*0Sstevel@tonic-gate /* n */ "unknown", 265*0Sstevel@tonic-gate /* n */ "unknown", 266*0Sstevel@tonic-gate /* n */ "unknown", 267*0Sstevel@tonic-gate /* n */ "unknown", 268*0Sstevel@tonic-gate /* n */ NULL 269*0Sstevel@tonic-gate }; 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate static char * 272*0Sstevel@tonic-gate pci_bridge [] = { 273*0Sstevel@tonic-gate /* n */ "hostpci", 274*0Sstevel@tonic-gate /* n */ "pci-isa", 275*0Sstevel@tonic-gate /* n */ "pcieisa", 276*0Sstevel@tonic-gate /* n */ "pci-mca", 277*0Sstevel@tonic-gate /* n */ "pci-pci", 278*0Sstevel@tonic-gate /* n */ "pcipcmc", 279*0Sstevel@tonic-gate /* n */ "pcinubu", 280*0Sstevel@tonic-gate /* n */ "pcicard", 281*0Sstevel@tonic-gate /* n */ "pcirace", 282*0Sstevel@tonic-gate /* n */ "stpci", 283*0Sstevel@tonic-gate /* n */ NULL 284*0Sstevel@tonic-gate }; 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate static char * 287*0Sstevel@tonic-gate pci_comm [] = { 288*0Sstevel@tonic-gate /* n */ "serial", 289*0Sstevel@tonic-gate /* n */ "paralle", 290*0Sstevel@tonic-gate /* n */ "multise", 291*0Sstevel@tonic-gate /* n */ "modem", 292*0Sstevel@tonic-gate /* n */ "unknown", 293*0Sstevel@tonic-gate /* n */ "unknown", 294*0Sstevel@tonic-gate /* n */ "unknown", 295*0Sstevel@tonic-gate /* n */ "unknown", 296*0Sstevel@tonic-gate /* n */ "unknown", 297*0Sstevel@tonic-gate /* n */ "unknown", 298*0Sstevel@tonic-gate /* n */ NULL 299*0Sstevel@tonic-gate }; 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate static char * 302*0Sstevel@tonic-gate pci_periph [] = { 303*0Sstevel@tonic-gate /* n */ "pic", 304*0Sstevel@tonic-gate /* n */ "dma", 305*0Sstevel@tonic-gate /* n */ "timer", 306*0Sstevel@tonic-gate /* n */ "rtc", 307*0Sstevel@tonic-gate /* n */ "unknown", 308*0Sstevel@tonic-gate /* n */ "unknown", 309*0Sstevel@tonic-gate /* n */ "unknown", 310*0Sstevel@tonic-gate /* n */ "unknown", 311*0Sstevel@tonic-gate /* n */ "unknown", 312*0Sstevel@tonic-gate /* n */ "unknown", 313*0Sstevel@tonic-gate /* n */ NULL 314*0Sstevel@tonic-gate }; 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate static char * 317*0Sstevel@tonic-gate pci_input [] = { 318*0Sstevel@tonic-gate /* n */ "keyboar", 319*0Sstevel@tonic-gate /* n */ "tablet", 320*0Sstevel@tonic-gate /* n */ "mouse", 321*0Sstevel@tonic-gate /* n */ "scanner", 322*0Sstevel@tonic-gate /* n */ "gamepor", 323*0Sstevel@tonic-gate /* n */ "unknown", 324*0Sstevel@tonic-gate /* n */ "unknown", 325*0Sstevel@tonic-gate /* n */ "unknown", 326*0Sstevel@tonic-gate /* n */ "unknown", 327*0Sstevel@tonic-gate /* n */ "unknown", 328*0Sstevel@tonic-gate /* n */ NULL 329*0Sstevel@tonic-gate }; 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate static char * 332*0Sstevel@tonic-gate pci_dock [] = { 333*0Sstevel@tonic-gate /* n */ "docking", 334*0Sstevel@tonic-gate /* n */ "unknown", 335*0Sstevel@tonic-gate /* n */ "unknown", 336*0Sstevel@tonic-gate /* n */ "unknown", 337*0Sstevel@tonic-gate /* n */ "unknown", 338*0Sstevel@tonic-gate /* n */ "unknown", 339*0Sstevel@tonic-gate /* n */ "unknown", 340*0Sstevel@tonic-gate /* n */ "unknown", 341*0Sstevel@tonic-gate /* n */ "unknown", 342*0Sstevel@tonic-gate /* n */ "unknown", 343*0Sstevel@tonic-gate /* n */ NULL 344*0Sstevel@tonic-gate }; 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate static char * 347*0Sstevel@tonic-gate pci_processor [] = { 348*0Sstevel@tonic-gate /* n */ "386", 349*0Sstevel@tonic-gate /* n */ "486", 350*0Sstevel@tonic-gate /* n */ "pentium", 351*0Sstevel@tonic-gate /* n */ "alpha", 352*0Sstevel@tonic-gate /* n */ "powerpc", 353*0Sstevel@tonic-gate /* n */ "mips", 354*0Sstevel@tonic-gate /* n */ "coproc", 355*0Sstevel@tonic-gate /* n */ "unknown", 356*0Sstevel@tonic-gate /* n */ "unknown", 357*0Sstevel@tonic-gate /* n */ "unknown", 358*0Sstevel@tonic-gate /* n */ NULL 359*0Sstevel@tonic-gate }; 360*0Sstevel@tonic-gate 361*0Sstevel@tonic-gate static char * 362*0Sstevel@tonic-gate pci_serial [] = { 363*0Sstevel@tonic-gate /* n */ "1394", 364*0Sstevel@tonic-gate /* n */ "access", 365*0Sstevel@tonic-gate /* n */ "ssa", 366*0Sstevel@tonic-gate /* n */ "usb", 367*0Sstevel@tonic-gate /* n */ "fibre", 368*0Sstevel@tonic-gate /* n */ "smbus", 369*0Sstevel@tonic-gate /* n */ "unknown", 370*0Sstevel@tonic-gate /* n */ "unknown", 371*0Sstevel@tonic-gate /* n */ "unknown", 372*0Sstevel@tonic-gate /* n */ "unknown", 373*0Sstevel@tonic-gate /* n */ NULL 374*0Sstevel@tonic-gate }; 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate static char * 377*0Sstevel@tonic-gate pci_wireless [] = { 378*0Sstevel@tonic-gate /* n */ "irda", 379*0Sstevel@tonic-gate /* n */ "ir", 380*0Sstevel@tonic-gate /* n */ "rf", 381*0Sstevel@tonic-gate /* n */ "unknown", 382*0Sstevel@tonic-gate /* n */ "unknown", 383*0Sstevel@tonic-gate /* n */ "unknown", 384*0Sstevel@tonic-gate /* n */ "unknown", 385*0Sstevel@tonic-gate /* n */ "unknown", 386*0Sstevel@tonic-gate /* n */ "unknown", 387*0Sstevel@tonic-gate /* n */ "unknown", 388*0Sstevel@tonic-gate /* n */ NULL 389*0Sstevel@tonic-gate }; 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate static char * 392*0Sstevel@tonic-gate pci_intio [] = { 393*0Sstevel@tonic-gate /* n */ "i2o", 394*0Sstevel@tonic-gate /* n */ "unknown", 395*0Sstevel@tonic-gate /* n */ "unknown", 396*0Sstevel@tonic-gate /* n */ "unknown", 397*0Sstevel@tonic-gate /* n */ "unknown", 398*0Sstevel@tonic-gate /* n */ "unknown", 399*0Sstevel@tonic-gate /* n */ "unknown", 400*0Sstevel@tonic-gate /* n */ "unknown", 401*0Sstevel@tonic-gate /* n */ "unknown", 402*0Sstevel@tonic-gate /* n */ "unknown", 403*0Sstevel@tonic-gate /* n */ NULL 404*0Sstevel@tonic-gate }; 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate static char * 407*0Sstevel@tonic-gate pci_satellite [] = { 408*0Sstevel@tonic-gate /* n */ "tv", 409*0Sstevel@tonic-gate /* n */ "audio", 410*0Sstevel@tonic-gate /* n */ "voice", 411*0Sstevel@tonic-gate /* n */ "data", 412*0Sstevel@tonic-gate /* n */ "unknown", 413*0Sstevel@tonic-gate /* n */ "unknown", 414*0Sstevel@tonic-gate /* n */ "unknown", 415*0Sstevel@tonic-gate /* n */ "unknown", 416*0Sstevel@tonic-gate /* n */ "unknown", 417*0Sstevel@tonic-gate /* n */ "unknown", 418*0Sstevel@tonic-gate /* n */ NULL 419*0Sstevel@tonic-gate }; 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate static char * 422*0Sstevel@tonic-gate pci_crypt [] = { 423*0Sstevel@tonic-gate /* n */ "netcryp", 424*0Sstevel@tonic-gate /* n */ "entcryp", 425*0Sstevel@tonic-gate /* n */ "unknown", 426*0Sstevel@tonic-gate /* n */ "unknown", 427*0Sstevel@tonic-gate /* n */ "unknown", 428*0Sstevel@tonic-gate /* n */ "unknown", 429*0Sstevel@tonic-gate /* n */ "unknown", 430*0Sstevel@tonic-gate /* n */ "unknown", 431*0Sstevel@tonic-gate /* n */ "unknown", 432*0Sstevel@tonic-gate /* n */ "unknown", 433*0Sstevel@tonic-gate /* n */ NULL 434*0Sstevel@tonic-gate }; 435*0Sstevel@tonic-gate 436*0Sstevel@tonic-gate static char * 437*0Sstevel@tonic-gate pci_signal [] = { 438*0Sstevel@tonic-gate /* n */ "dpio", 439*0Sstevel@tonic-gate /* n */ "unknown", 440*0Sstevel@tonic-gate /* n */ "unknown", 441*0Sstevel@tonic-gate /* n */ "unknown", 442*0Sstevel@tonic-gate /* n */ "unknown", 443*0Sstevel@tonic-gate /* n */ "unknown", 444*0Sstevel@tonic-gate /* n */ "unknown", 445*0Sstevel@tonic-gate /* n */ "unknown", 446*0Sstevel@tonic-gate /* n */ "unknown", 447*0Sstevel@tonic-gate /* n */ "unknown", 448*0Sstevel@tonic-gate /* n */ NULL 449*0Sstevel@tonic-gate }; 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate /* 452*0Sstevel@tonic-gate * Board Type 453*0Sstevel@tonic-gate */ 454*0Sstevel@tonic-gate static char * 455*0Sstevel@tonic-gate board_strs[] = { 456*0Sstevel@tonic-gate /* n */ "???", /* HPC_BOARD_UNKNOWN */ 457*0Sstevel@tonic-gate /* n */ "hp", /* HPC_BOARD_PCI_HOTPLUG */ 458*0Sstevel@tonic-gate /* n */ "nhs", /* HPC_BOARD_CPCI_NON_HS */ 459*0Sstevel@tonic-gate /* n */ "bhs", /* HPC_BOARD_CPCI_BASIC_HS */ 460*0Sstevel@tonic-gate /* n */ "fhs", /* HPC_BOARD_CPCI_FULL_HS */ 461*0Sstevel@tonic-gate /* n */ "hs", /* HPC_BOARD_CPCI_HS */ 462*0Sstevel@tonic-gate /* n */ NULL 463*0Sstevel@tonic-gate }; 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate /* 466*0Sstevel@tonic-gate * HW functions 467*0Sstevel@tonic-gate */ 468*0Sstevel@tonic-gate static char * 469*0Sstevel@tonic-gate func_strs[] = { 470*0Sstevel@tonic-gate /* n */ "enable_slot", 471*0Sstevel@tonic-gate /* n */ "disable_slot", 472*0Sstevel@tonic-gate /* n */ "enable_autoconfig", 473*0Sstevel@tonic-gate /* n */ "disable_autoconfig", 474*0Sstevel@tonic-gate /* n */ "led", 475*0Sstevel@tonic-gate /* n */ "mode", 476*0Sstevel@tonic-gate /* n */ NULL 477*0Sstevel@tonic-gate }; 478*0Sstevel@tonic-gate 479*0Sstevel@tonic-gate #define PCISO_SUBCLASS_OTHER 0x80 /* generic subclass */ 480*0Sstevel@tonic-gate 481*0Sstevel@tonic-gate /* 482*0Sstevel@tonic-gate * other subclass types 483*0Sstevel@tonic-gate */ 484*0Sstevel@tonic-gate 485*0Sstevel@tonic-gate static char * 486*0Sstevel@tonic-gate other_strs[] = { 487*0Sstevel@tonic-gate /* n */ "none", 488*0Sstevel@tonic-gate /* n */ "storage", 489*0Sstevel@tonic-gate /* n */ "network", 490*0Sstevel@tonic-gate /* n */ "display", 491*0Sstevel@tonic-gate /* n */ "mmedia", 492*0Sstevel@tonic-gate /* n */ "memory", 493*0Sstevel@tonic-gate /* n */ "bridge", 494*0Sstevel@tonic-gate /* n */ "unknown", 495*0Sstevel@tonic-gate /* n */ "unknown", 496*0Sstevel@tonic-gate /* n */ "unknown", 497*0Sstevel@tonic-gate /* n */ NULL 498*0Sstevel@tonic-gate }; 499*0Sstevel@tonic-gate 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate #define ENABLE_SLOT 0 502*0Sstevel@tonic-gate #define DISABLE_SLOT 1 503*0Sstevel@tonic-gate #define ENABLE_AUTOCNF 2 504*0Sstevel@tonic-gate #define DISABLE_AUTOCNF 3 505*0Sstevel@tonic-gate #define LED 4 506*0Sstevel@tonic-gate #define MODE 5 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate /* 509*0Sstevel@tonic-gate * LED strings 510*0Sstevel@tonic-gate */ 511*0Sstevel@tonic-gate static char * 512*0Sstevel@tonic-gate led_strs[] = { 513*0Sstevel@tonic-gate /* n */ "fault", /* HPC_FAULT_LED */ 514*0Sstevel@tonic-gate /* n */ "power", /* HPC_POWER_LED */ 515*0Sstevel@tonic-gate /* n */ "attn", /* HPC_ATTN_LED */ 516*0Sstevel@tonic-gate /* n */ "active", /* HPC_ACTIVE_LED */ 517*0Sstevel@tonic-gate /* n */ NULL 518*0Sstevel@tonic-gate }; 519*0Sstevel@tonic-gate 520*0Sstevel@tonic-gate #define FAULT 0 521*0Sstevel@tonic-gate #define POWER 1 522*0Sstevel@tonic-gate #define ATTN 2 523*0Sstevel@tonic-gate #define ACTIVE 3 524*0Sstevel@tonic-gate 525*0Sstevel@tonic-gate static char * 526*0Sstevel@tonic-gate mode_strs[] = { 527*0Sstevel@tonic-gate /* n */ "off", /* HPC_LED_OFF */ 528*0Sstevel@tonic-gate /* n */ "on", /* HPC_LED_ON */ 529*0Sstevel@tonic-gate /* n */ "blink", /* HPC_LED_BLINK */ 530*0Sstevel@tonic-gate /* n */ NULL 531*0Sstevel@tonic-gate }; 532*0Sstevel@tonic-gate 533*0Sstevel@tonic-gate #define OFF 0 534*0Sstevel@tonic-gate #define ON 1 535*0Sstevel@tonic-gate #define BLINK 2 536*0Sstevel@tonic-gate 537*0Sstevel@tonic-gate #define cfga_errstrs(i) cfga_errstrs[(i)] 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate #define cfga_eid(a, b) (((a) << 8) + (b)) 540*0Sstevel@tonic-gate #define MAXDEVS 32 541*0Sstevel@tonic-gate 542*0Sstevel@tonic-gate typedef enum { 543*0Sstevel@tonic-gate SOLARIS_SLT_NAME, 544*0Sstevel@tonic-gate PROM_SLT_NAME 545*0Sstevel@tonic-gate } slt_name_src_t; 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate struct searcharg { 548*0Sstevel@tonic-gate char *devpath; 549*0Sstevel@tonic-gate char slotnames[MAXDEVS][MAXNAMELEN]; 550*0Sstevel@tonic-gate int minor; 551*0Sstevel@tonic-gate di_prom_handle_t promp; 552*0Sstevel@tonic-gate slt_name_src_t slt_name_src; 553*0Sstevel@tonic-gate }; 554*0Sstevel@tonic-gate 555*0Sstevel@tonic-gate static void *private_check; 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate static int 558*0Sstevel@tonic-gate get_occupants(const char *ap_id, hpc_occupant_info_t *occupant) 559*0Sstevel@tonic-gate { 560*0Sstevel@tonic-gate int rv; 561*0Sstevel@tonic-gate int fd; 562*0Sstevel@tonic-gate di_node_t ap_node; 563*0Sstevel@tonic-gate char *prop_data; 564*0Sstevel@tonic-gate char *tmp; 565*0Sstevel@tonic-gate char *ptr; 566*0Sstevel@tonic-gate struct stat statbuf; 567*0Sstevel@tonic-gate dev_t devt; 568*0Sstevel@tonic-gate 569*0Sstevel@tonic-gate if ((fd = open(ap_id, O_RDWR)) == -1) { 570*0Sstevel@tonic-gate DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd)); 571*0Sstevel@tonic-gate DBG_F(2, (stderr, "open on %s failed\n", ap_id)); 572*0Sstevel@tonic-gate return (CFGA_ERROR); 573*0Sstevel@tonic-gate } 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate if (fstat(fd, &statbuf) == -1) { 576*0Sstevel@tonic-gate DBG(1, ("stat failed: %i\n", errno)); 577*0Sstevel@tonic-gate (void) close(fd); 578*0Sstevel@tonic-gate return (CFGA_ERROR); 579*0Sstevel@tonic-gate } 580*0Sstevel@tonic-gate (void) close(fd); 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate devt = statbuf.st_rdev; 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate tmp = (char *)(ap_id + sizeof ("/devices") - 1); 585*0Sstevel@tonic-gate if ((ptr = strrchr(tmp, ':')) != NULL) 586*0Sstevel@tonic-gate *ptr = '\0'; 587*0Sstevel@tonic-gate 588*0Sstevel@tonic-gate ap_node = di_init(tmp, DINFOPROP | DINFOMINOR); 589*0Sstevel@tonic-gate if (ap_node == DI_NODE_NIL) { 590*0Sstevel@tonic-gate DBG(1, ("dead %i\n", errno)); 591*0Sstevel@tonic-gate return (CFGA_ERROR); 592*0Sstevel@tonic-gate } 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate #ifdef PCIHP_DBG 595*0Sstevel@tonic-gate ptr = di_devfs_path(ap_node); 596*0Sstevel@tonic-gate DBG(1, ("get_occupants: %s\n", ptr)); 597*0Sstevel@tonic-gate di_devfs_path_free(ptr); 598*0Sstevel@tonic-gate #endif 599*0Sstevel@tonic-gate 600*0Sstevel@tonic-gate if ((rv = di_prop_lookup_strings(devt, ap_node, "pci-occupant", 601*0Sstevel@tonic-gate &prop_data)) == -1) { 602*0Sstevel@tonic-gate DBG(1, ("get_occupants: prop_lookup failed: %i\n", errno)); 603*0Sstevel@tonic-gate di_fini(ap_node); 604*0Sstevel@tonic-gate return (CFGA_ERROR); 605*0Sstevel@tonic-gate } 606*0Sstevel@tonic-gate 607*0Sstevel@tonic-gate if (prop_data && (strcmp(prop_data, "") == 0)) { 608*0Sstevel@tonic-gate di_fini(ap_node); 609*0Sstevel@tonic-gate occupant->i = 0; 610*0Sstevel@tonic-gate occupant->id[0] = NULL; 611*0Sstevel@tonic-gate return (CFGA_OK); 612*0Sstevel@tonic-gate } 613*0Sstevel@tonic-gate 614*0Sstevel@tonic-gate DBG(1, ("get_occupants: %i devices found\n", rv)); 615*0Sstevel@tonic-gate for (occupant->i = 0; occupant->i < rv; occupant->i++) { 616*0Sstevel@tonic-gate if (occupant->i >= (HPC_MAX_OCCUPANTS - 1)) { 617*0Sstevel@tonic-gate occupant->i--; 618*0Sstevel@tonic-gate break; 619*0Sstevel@tonic-gate } 620*0Sstevel@tonic-gate occupant->id[occupant->i] = (char *)malloc( 621*0Sstevel@tonic-gate strlen(prop_data) + sizeof ("/devices")); 622*0Sstevel@tonic-gate (void) snprintf(occupant->id[occupant->i], strlen(prop_data) + 623*0Sstevel@tonic-gate sizeof ("/devices"), "/devices%s", prop_data); 624*0Sstevel@tonic-gate DBG(1, ("%s\n", occupant->id[occupant->i])); 625*0Sstevel@tonic-gate prop_data += strlen(prop_data) + 1; 626*0Sstevel@tonic-gate } 627*0Sstevel@tonic-gate di_fini(ap_node); 628*0Sstevel@tonic-gate 629*0Sstevel@tonic-gate occupant->id[occupant->i] = NULL; 630*0Sstevel@tonic-gate 631*0Sstevel@tonic-gate return (CFGA_OK); 632*0Sstevel@tonic-gate } 633*0Sstevel@tonic-gate 634*0Sstevel@tonic-gate /* 635*0Sstevel@tonic-gate * let rcm know that the device has indeed been removed and clean 636*0Sstevel@tonic-gate * up rcm data 637*0Sstevel@tonic-gate */ 638*0Sstevel@tonic-gate static void 639*0Sstevel@tonic-gate confirm_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle) 640*0Sstevel@tonic-gate { 641*0Sstevel@tonic-gate DBG(1, ("confirm_rcm\n")); 642*0Sstevel@tonic-gate 643*0Sstevel@tonic-gate if (occupant->i == 0) /* nothing was found to ask rcm about */ 644*0Sstevel@tonic-gate return; 645*0Sstevel@tonic-gate 646*0Sstevel@tonic-gate (void) rcm_notify_remove_list(rhandle, occupant->id, 0, NULL); 647*0Sstevel@tonic-gate (void) rcm_free_handle(rhandle); 648*0Sstevel@tonic-gate 649*0Sstevel@tonic-gate for (; occupant->i >= 0; occupant->i--) 650*0Sstevel@tonic-gate free(occupant->id[occupant->i]); 651*0Sstevel@tonic-gate } 652*0Sstevel@tonic-gate 653*0Sstevel@tonic-gate static void 654*0Sstevel@tonic-gate fail_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle) 655*0Sstevel@tonic-gate { 656*0Sstevel@tonic-gate DBG(1, ("fail_rcm\n")); 657*0Sstevel@tonic-gate 658*0Sstevel@tonic-gate if (occupant->i == 0) /* nothing was found to ask rcm about */ 659*0Sstevel@tonic-gate return; 660*0Sstevel@tonic-gate 661*0Sstevel@tonic-gate (void) rcm_notify_online_list(rhandle, occupant->id, 0, NULL); 662*0Sstevel@tonic-gate (void) rcm_free_handle(rhandle); 663*0Sstevel@tonic-gate 664*0Sstevel@tonic-gate for (; occupant->i >= 0; occupant->i--) 665*0Sstevel@tonic-gate free(occupant->id[occupant->i]); 666*0Sstevel@tonic-gate } 667*0Sstevel@tonic-gate 668*0Sstevel@tonic-gate /* 669*0Sstevel@tonic-gate * copied from scsi_rcm_info_table 670*0Sstevel@tonic-gate * 671*0Sstevel@tonic-gate * Takes an opaque rcm_info_t pointer and a character pointer, and appends 672*0Sstevel@tonic-gate * the rcm_info_t data in the form of a table to the given character pointer. 673*0Sstevel@tonic-gate */ 674*0Sstevel@tonic-gate static void 675*0Sstevel@tonic-gate pci_rcm_info_table(rcm_info_t *rinfo, char **table) 676*0Sstevel@tonic-gate { 677*0Sstevel@tonic-gate int i; 678*0Sstevel@tonic-gate size_t w; 679*0Sstevel@tonic-gate size_t width = 0; 680*0Sstevel@tonic-gate size_t w_rsrc = 0; 681*0Sstevel@tonic-gate size_t w_info = 0; 682*0Sstevel@tonic-gate size_t table_size = 0; 683*0Sstevel@tonic-gate uint_t tuples = 0; 684*0Sstevel@tonic-gate rcm_info_tuple_t *tuple = NULL; 685*0Sstevel@tonic-gate char *rsrc; 686*0Sstevel@tonic-gate char *info; 687*0Sstevel@tonic-gate char *newtable; 688*0Sstevel@tonic-gate static char format[MAX_FORMAT]; 689*0Sstevel@tonic-gate const char *infostr; 690*0Sstevel@tonic-gate 691*0Sstevel@tonic-gate /* Protect against invalid arguments */ 692*0Sstevel@tonic-gate if (rinfo == NULL || table == NULL) 693*0Sstevel@tonic-gate return; 694*0Sstevel@tonic-gate 695*0Sstevel@tonic-gate /* Set localized table header strings */ 696*0Sstevel@tonic-gate rsrc = dgettext(TEXT_DOMAIN, "Resource"); 697*0Sstevel@tonic-gate info = dgettext(TEXT_DOMAIN, "Information"); 698*0Sstevel@tonic-gate 699*0Sstevel@tonic-gate /* A first pass, to size up the RCM information */ 700*0Sstevel@tonic-gate while (tuple = rcm_info_next(rinfo, tuple)) { 701*0Sstevel@tonic-gate if ((infostr = rcm_info_info(tuple)) != NULL) { 702*0Sstevel@tonic-gate tuples++; 703*0Sstevel@tonic-gate if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc) 704*0Sstevel@tonic-gate w_rsrc = w; 705*0Sstevel@tonic-gate if ((w = strlen(infostr)) > w_info) 706*0Sstevel@tonic-gate w_info = w; 707*0Sstevel@tonic-gate } 708*0Sstevel@tonic-gate } 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate /* If nothing was sized up above, stop early */ 711*0Sstevel@tonic-gate if (tuples == 0) 712*0Sstevel@tonic-gate return; 713*0Sstevel@tonic-gate 714*0Sstevel@tonic-gate /* Adjust column widths for column headings */ 715*0Sstevel@tonic-gate if ((w = strlen(rsrc)) > w_rsrc) 716*0Sstevel@tonic-gate w_rsrc = w; 717*0Sstevel@tonic-gate else if ((w_rsrc - w) % 2) 718*0Sstevel@tonic-gate w_rsrc++; 719*0Sstevel@tonic-gate if ((w = strlen(info)) > w_info) 720*0Sstevel@tonic-gate w_info = w; 721*0Sstevel@tonic-gate else if ((w_info - w) % 2) 722*0Sstevel@tonic-gate w_info++; 723*0Sstevel@tonic-gate 724*0Sstevel@tonic-gate /* 725*0Sstevel@tonic-gate * Compute the total line width of each line, 726*0Sstevel@tonic-gate * accounting for intercolumn spacing. 727*0Sstevel@tonic-gate */ 728*0Sstevel@tonic-gate width = w_info + w_rsrc + 4; 729*0Sstevel@tonic-gate 730*0Sstevel@tonic-gate /* Allocate space for the table */ 731*0Sstevel@tonic-gate table_size = (2 + tuples) * (width + 1) + 2; 732*0Sstevel@tonic-gate if (*table == NULL) { 733*0Sstevel@tonic-gate /* zero fill for the strcat() call below */ 734*0Sstevel@tonic-gate *table = calloc(table_size, sizeof (char)); 735*0Sstevel@tonic-gate if (*table == NULL) 736*0Sstevel@tonic-gate return; 737*0Sstevel@tonic-gate } else { 738*0Sstevel@tonic-gate newtable = realloc(*table, strlen(*table) + table_size); 739*0Sstevel@tonic-gate if (newtable == NULL) 740*0Sstevel@tonic-gate return; 741*0Sstevel@tonic-gate else 742*0Sstevel@tonic-gate *table = newtable; 743*0Sstevel@tonic-gate } 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gate /* Place a table header into the string */ 746*0Sstevel@tonic-gate 747*0Sstevel@tonic-gate /* The resource header */ 748*0Sstevel@tonic-gate (void) strcat(*table, "\n"); 749*0Sstevel@tonic-gate w = strlen(rsrc); 750*0Sstevel@tonic-gate for (i = 0; i < ((w_rsrc - w) / 2); i++) 751*0Sstevel@tonic-gate (void) strcat(*table, " "); 752*0Sstevel@tonic-gate (void) strcat(*table, rsrc); 753*0Sstevel@tonic-gate for (i = 0; i < ((w_rsrc - w) / 2); i++) 754*0Sstevel@tonic-gate (void) strcat(*table, " "); 755*0Sstevel@tonic-gate 756*0Sstevel@tonic-gate /* The information header */ 757*0Sstevel@tonic-gate (void) strcat(*table, " "); 758*0Sstevel@tonic-gate w = strlen(info); 759*0Sstevel@tonic-gate for (i = 0; i < ((w_info - w) / 2); i++) 760*0Sstevel@tonic-gate (void) strcat(*table, " "); 761*0Sstevel@tonic-gate (void) strcat(*table, info); 762*0Sstevel@tonic-gate for (i = 0; i < ((w_info - w) / 2); i++) 763*0Sstevel@tonic-gate (void) strcat(*table, " "); 764*0Sstevel@tonic-gate /* Underline the headers */ 765*0Sstevel@tonic-gate (void) strcat(*table, "\n"); 766*0Sstevel@tonic-gate for (i = 0; i < w_rsrc; i++) 767*0Sstevel@tonic-gate (void) strcat(*table, "-"); 768*0Sstevel@tonic-gate (void) strcat(*table, " "); 769*0Sstevel@tonic-gate for (i = 0; i < w_info; i++) 770*0Sstevel@tonic-gate (void) strcat(*table, "-"); 771*0Sstevel@tonic-gate 772*0Sstevel@tonic-gate /* Construct the format string */ 773*0Sstevel@tonic-gate (void) snprintf(format, MAX_FORMAT, "%%-%ds %%-%ds", 774*0Sstevel@tonic-gate (int)w_rsrc, (int)w_info); 775*0Sstevel@tonic-gate 776*0Sstevel@tonic-gate /* Add the tuples to the table string */ 777*0Sstevel@tonic-gate tuple = NULL; 778*0Sstevel@tonic-gate while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) { 779*0Sstevel@tonic-gate if ((infostr = rcm_info_info(tuple)) != NULL) { 780*0Sstevel@tonic-gate (void) strcat(*table, "\n"); 781*0Sstevel@tonic-gate (void) sprintf(&((*table)[strlen(*table)]), 782*0Sstevel@tonic-gate format, rcm_info_rsrc(tuple), 783*0Sstevel@tonic-gate infostr); 784*0Sstevel@tonic-gate } 785*0Sstevel@tonic-gate } 786*0Sstevel@tonic-gate } 787*0Sstevel@tonic-gate 788*0Sstevel@tonic-gate /* 789*0Sstevel@tonic-gate * Figure out what device is about to be unconfigured or disconnected 790*0Sstevel@tonic-gate * and make sure rcm is ok with it. 791*0Sstevel@tonic-gate * hangs on to a list of handles so they can then be confirmed or denied 792*0Sstevel@tonic-gate * if either getting the occupant list or talking to rcm fails 793*0Sstevel@tonic-gate * return CFGA_ERROR so that things can go on without rcm 794*0Sstevel@tonic-gate */ 795*0Sstevel@tonic-gate static int 796*0Sstevel@tonic-gate check_rcm(const char *ap_id, hpc_occupant_info_t *occupant, 797*0Sstevel@tonic-gate rcm_handle_t **rhandlep, char **errstring, cfga_flags_t flags) 798*0Sstevel@tonic-gate { 799*0Sstevel@tonic-gate int rv; 800*0Sstevel@tonic-gate rcm_info_t *rinfo; 801*0Sstevel@tonic-gate rcm_handle_t *rhandle; 802*0Sstevel@tonic-gate uint_t rcmflags; 803*0Sstevel@tonic-gate 804*0Sstevel@tonic-gate if (get_occupants(ap_id, occupant) != 0) { 805*0Sstevel@tonic-gate DBG(1, ("check_rcm: failed to get occupants\n")); 806*0Sstevel@tonic-gate return (CFGA_ERROR); 807*0Sstevel@tonic-gate } 808*0Sstevel@tonic-gate 809*0Sstevel@tonic-gate if (occupant->i == 0) { 810*0Sstevel@tonic-gate DBG(1, ("check_rcm: no drivers attaching to occupants\n")); 811*0Sstevel@tonic-gate return (CFGA_OK); 812*0Sstevel@tonic-gate } 813*0Sstevel@tonic-gate 814*0Sstevel@tonic-gate if (rcm_alloc_handle(NULL, 0, NULL, &rhandle) 815*0Sstevel@tonic-gate != RCM_SUCCESS) { 816*0Sstevel@tonic-gate DBG(1, ("check_rcm: blocked by rcm failure\n")); 817*0Sstevel@tonic-gate return (CFGA_ERROR); 818*0Sstevel@tonic-gate } 819*0Sstevel@tonic-gate 820*0Sstevel@tonic-gate rcmflags = (flags & CFGA_FLAG_FORCE) ? RCM_FORCE : 0; 821*0Sstevel@tonic-gate rv = rcm_request_offline_list(rhandle, occupant->id, rcmflags, &rinfo); 822*0Sstevel@tonic-gate 823*0Sstevel@tonic-gate if (rv == RCM_FAILURE) { 824*0Sstevel@tonic-gate DBG(1, ("check_rcm: blocked by rcm failure 2\n")); 825*0Sstevel@tonic-gate pci_rcm_info_table(rinfo, errstring); 826*0Sstevel@tonic-gate rcm_free_info(rinfo); 827*0Sstevel@tonic-gate fail_rcm(occupant, rhandle); 828*0Sstevel@tonic-gate return (CFGA_BUSY); 829*0Sstevel@tonic-gate } 830*0Sstevel@tonic-gate if (rv == RCM_CONFLICT) { 831*0Sstevel@tonic-gate DBG(1, ("check_rcm: blocked by %i\n", 832*0Sstevel@tonic-gate rcm_info_pid(rinfo))); 833*0Sstevel@tonic-gate pci_rcm_info_table(rinfo, errstring); 834*0Sstevel@tonic-gate rcm_free_info(rinfo); 835*0Sstevel@tonic-gate (void) rcm_free_handle(rhandle); 836*0Sstevel@tonic-gate for (; occupant->i >= 0; occupant->i--) 837*0Sstevel@tonic-gate free(occupant->id[occupant->i]); 838*0Sstevel@tonic-gate return (CFGA_BUSY); 839*0Sstevel@tonic-gate } 840*0Sstevel@tonic-gate 841*0Sstevel@tonic-gate rcm_free_info(rinfo); 842*0Sstevel@tonic-gate *rhandlep = rhandle; 843*0Sstevel@tonic-gate 844*0Sstevel@tonic-gate /* else */ 845*0Sstevel@tonic-gate return (CFGA_OK); 846*0Sstevel@tonic-gate } 847*0Sstevel@tonic-gate 848*0Sstevel@tonic-gate 849*0Sstevel@tonic-gate /* 850*0Sstevel@tonic-gate * Transitional Diagram: 851*0Sstevel@tonic-gate * 852*0Sstevel@tonic-gate * empty unconfigure 853*0Sstevel@tonic-gate * (remove) ^| (physically insert card) 854*0Sstevel@tonic-gate * |V 855*0Sstevel@tonic-gate * disconnect configure 856*0Sstevel@tonic-gate * "-c DISCONNECT" ^| "-c CONNECT" 857*0Sstevel@tonic-gate * |V "-c CONFIGURE" 858*0Sstevel@tonic-gate * connect unconfigure -> connect configure 859*0Sstevel@tonic-gate * <- 860*0Sstevel@tonic-gate * "-c UNCONFIGURE" 861*0Sstevel@tonic-gate * 862*0Sstevel@tonic-gate */ 863*0Sstevel@tonic-gate /*ARGSUSED*/ 864*0Sstevel@tonic-gate cfga_err_t 865*0Sstevel@tonic-gate cfga_change_state(cfga_cmd_t state_change_cmd, const char *ap_id, 866*0Sstevel@tonic-gate const char *options, struct cfga_confirm *confp, 867*0Sstevel@tonic-gate struct cfga_msg *msgp, char **errstring, cfga_flags_t flags) 868*0Sstevel@tonic-gate { 869*0Sstevel@tonic-gate int rv; 870*0Sstevel@tonic-gate devctl_hdl_t dcp; 871*0Sstevel@tonic-gate devctl_ap_state_t state; 872*0Sstevel@tonic-gate ap_rstate_t rs; 873*0Sstevel@tonic-gate ap_ostate_t os; 874*0Sstevel@tonic-gate hpc_occupant_info_t occupants; 875*0Sstevel@tonic-gate rcm_handle_t *rhandle; 876*0Sstevel@tonic-gate 877*0Sstevel@tonic-gate if ((rv = check_options(options)) != CFGA_OK) { 878*0Sstevel@tonic-gate return (rv); 879*0Sstevel@tonic-gate } 880*0Sstevel@tonic-gate 881*0Sstevel@tonic-gate if (errstring != NULL) 882*0Sstevel@tonic-gate *errstring = NULL; 883*0Sstevel@tonic-gate 884*0Sstevel@tonic-gate rv = CFGA_OK; 885*0Sstevel@tonic-gate DBG(1, ("cfga_change_state:(%s)\n", ap_id)); 886*0Sstevel@tonic-gate 887*0Sstevel@tonic-gate if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) { 888*0Sstevel@tonic-gate if (rv == EBUSY) { 889*0Sstevel@tonic-gate cfga_err(errstring, CMD_ACQUIRE, ap_id, 0); 890*0Sstevel@tonic-gate DBG(1, ("cfga_change_state: device is busy\n")); 891*0Sstevel@tonic-gate rv = CFGA_BUSY; 892*0Sstevel@tonic-gate } else 893*0Sstevel@tonic-gate rv = CFGA_ERROR; 894*0Sstevel@tonic-gate return (rv); 895*0Sstevel@tonic-gate } 896*0Sstevel@tonic-gate 897*0Sstevel@tonic-gate if (devctl_ap_getstate(dcp, NULL, &state) == -1) { 898*0Sstevel@tonic-gate DBG(2, ("cfga_change_state: devctl ap getstate failed\n")); 899*0Sstevel@tonic-gate cfga_err(errstring, CMD_GETSTAT, ap_id, 0); 900*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 901*0Sstevel@tonic-gate if (rv == EBUSY) 902*0Sstevel@tonic-gate rv = CFGA_BUSY; 903*0Sstevel@tonic-gate else 904*0Sstevel@tonic-gate rv = CFGA_ERROR; 905*0Sstevel@tonic-gate return (rv); 906*0Sstevel@tonic-gate } 907*0Sstevel@tonic-gate 908*0Sstevel@tonic-gate rs = state.ap_rstate; 909*0Sstevel@tonic-gate os = state.ap_ostate; 910*0Sstevel@tonic-gate 911*0Sstevel@tonic-gate DBG(1, ("cfga_change_state: rs is %d\n", state.ap_rstate)); 912*0Sstevel@tonic-gate DBG(1, ("cfga_change_state: os is %d\n", state.ap_ostate)); 913*0Sstevel@tonic-gate switch (state_change_cmd) { 914*0Sstevel@tonic-gate case CFGA_CMD_CONNECT: 915*0Sstevel@tonic-gate if ((rs == AP_RSTATE_CONNECTED) || 916*0Sstevel@tonic-gate (os == AP_OSTATE_CONFIGURED)) { 917*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, 0); 918*0Sstevel@tonic-gate rv = CFGA_INVAL; 919*0Sstevel@tonic-gate } else { 920*0Sstevel@tonic-gate /* Lets connect the slot */ 921*0Sstevel@tonic-gate if (devctl_ap_connect(dcp, NULL) == -1) { 922*0Sstevel@tonic-gate rv = CFGA_ERROR; 923*0Sstevel@tonic-gate cfga_err(errstring, 924*0Sstevel@tonic-gate CMD_SLOT_CONNECT, 0); 925*0Sstevel@tonic-gate } 926*0Sstevel@tonic-gate } 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate break; 929*0Sstevel@tonic-gate 930*0Sstevel@tonic-gate case CFGA_CMD_DISCONNECT: 931*0Sstevel@tonic-gate DBG(1, ("disconnect\n")); 932*0Sstevel@tonic-gate 933*0Sstevel@tonic-gate if (os == AP_OSTATE_CONFIGURED) { 934*0Sstevel@tonic-gate if ((rv = check_rcm(ap_id, &occupants, &rhandle, 935*0Sstevel@tonic-gate errstring, flags)) == CFGA_BUSY) { 936*0Sstevel@tonic-gate break; 937*0Sstevel@tonic-gate } else if (rv == CFGA_OK) { 938*0Sstevel@tonic-gate if (devctl_ap_unconfigure(dcp, NULL) == -1) { 939*0Sstevel@tonic-gate if (errno == EBUSY) 940*0Sstevel@tonic-gate rv = CFGA_BUSY; 941*0Sstevel@tonic-gate else 942*0Sstevel@tonic-gate rv = CFGA_ERROR; 943*0Sstevel@tonic-gate cfga_err(errstring, 944*0Sstevel@tonic-gate CMD_SLOT_DISCONNECT, 0); 945*0Sstevel@tonic-gate fail_rcm(&occupants, rhandle); 946*0Sstevel@tonic-gate break; 947*0Sstevel@tonic-gate } else { 948*0Sstevel@tonic-gate confirm_rcm(&occupants, rhandle); 949*0Sstevel@tonic-gate } 950*0Sstevel@tonic-gate } else { /* rv == CFGA_ERROR */ 951*0Sstevel@tonic-gate if (devctl_ap_unconfigure(dcp, NULL) == -1) { 952*0Sstevel@tonic-gate if (errno == EBUSY) 953*0Sstevel@tonic-gate rv = CFGA_BUSY; 954*0Sstevel@tonic-gate else 955*0Sstevel@tonic-gate rv = CFGA_ERROR; 956*0Sstevel@tonic-gate break; 957*0Sstevel@tonic-gate } else { 958*0Sstevel@tonic-gate rv = CFGA_OK; 959*0Sstevel@tonic-gate } 960*0Sstevel@tonic-gate } 961*0Sstevel@tonic-gate } 962*0Sstevel@tonic-gate 963*0Sstevel@tonic-gate if (rs == AP_RSTATE_CONNECTED) { 964*0Sstevel@tonic-gate if (devctl_ap_disconnect(dcp, NULL) == -1) { 965*0Sstevel@tonic-gate rv = CFGA_ERROR; 966*0Sstevel@tonic-gate cfga_err(errstring, CMD_SLOT_DISCONNECT, 0); 967*0Sstevel@tonic-gate break; 968*0Sstevel@tonic-gate } 969*0Sstevel@tonic-gate } else { 970*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, 0); 971*0Sstevel@tonic-gate rv = CFGA_INVAL; 972*0Sstevel@tonic-gate } 973*0Sstevel@tonic-gate 974*0Sstevel@tonic-gate break; 975*0Sstevel@tonic-gate 976*0Sstevel@tonic-gate case CFGA_CMD_CONFIGURE: 977*0Sstevel@tonic-gate if (rs == AP_RSTATE_DISCONNECTED) { 978*0Sstevel@tonic-gate if (devctl_ap_connect(dcp, NULL) == -1) { 979*0Sstevel@tonic-gate rv = CFGA_ERROR; 980*0Sstevel@tonic-gate cfga_err(errstring, CMD_SLOT_CONNECT, 0); 981*0Sstevel@tonic-gate break; 982*0Sstevel@tonic-gate } 983*0Sstevel@tonic-gate } 984*0Sstevel@tonic-gate 985*0Sstevel@tonic-gate /* 986*0Sstevel@tonic-gate * for multi-func device we allow multiple 987*0Sstevel@tonic-gate * configure on the same slot because one 988*0Sstevel@tonic-gate * func can be configured and other one won't 989*0Sstevel@tonic-gate */ 990*0Sstevel@tonic-gate if (devctl_ap_configure(dcp, NULL) == -1) { 991*0Sstevel@tonic-gate rv = CFGA_ERROR; 992*0Sstevel@tonic-gate cfga_err(errstring, CMD_SLOT_CONFIGURE, 0); 993*0Sstevel@tonic-gate if (devctl_ap_disconnect(dcp, NULL) == -1) { 994*0Sstevel@tonic-gate rv = CFGA_ERROR; 995*0Sstevel@tonic-gate cfga_err(errstring, 996*0Sstevel@tonic-gate CMD_SLOT_CONFIGURE, 0); 997*0Sstevel@tonic-gate } 998*0Sstevel@tonic-gate break; 999*0Sstevel@tonic-gate } 1000*0Sstevel@tonic-gate 1001*0Sstevel@tonic-gate break; 1002*0Sstevel@tonic-gate 1003*0Sstevel@tonic-gate case CFGA_CMD_UNCONFIGURE: 1004*0Sstevel@tonic-gate DBG(1, ("unconfigure\n")); 1005*0Sstevel@tonic-gate 1006*0Sstevel@tonic-gate if (os == AP_OSTATE_CONFIGURED) { 1007*0Sstevel@tonic-gate if ((rv = check_rcm(ap_id, &occupants, &rhandle, 1008*0Sstevel@tonic-gate errstring, flags)) == CFGA_BUSY) { 1009*0Sstevel@tonic-gate break; 1010*0Sstevel@tonic-gate } else if (rv == CFGA_OK) { 1011*0Sstevel@tonic-gate if (devctl_ap_unconfigure(dcp, NULL) == -1) { 1012*0Sstevel@tonic-gate if (errno == EBUSY) 1013*0Sstevel@tonic-gate rv = CFGA_BUSY; 1014*0Sstevel@tonic-gate else { 1015*0Sstevel@tonic-gate if (errno == ENOTSUP) 1016*0Sstevel@tonic-gate rv = CFGA_OPNOTSUPP; 1017*0Sstevel@tonic-gate else 1018*0Sstevel@tonic-gate rv = CFGA_ERROR; 1019*0Sstevel@tonic-gate } 1020*0Sstevel@tonic-gate cfga_err(errstring, 1021*0Sstevel@tonic-gate CMD_SLOT_UNCONFIGURE, 0); 1022*0Sstevel@tonic-gate fail_rcm(&occupants, rhandle); 1023*0Sstevel@tonic-gate } else { 1024*0Sstevel@tonic-gate confirm_rcm(&occupants, rhandle); 1025*0Sstevel@tonic-gate } 1026*0Sstevel@tonic-gate } else { /* rv == CFGA_ERROR */ 1027*0Sstevel@tonic-gate if (devctl_ap_unconfigure(dcp, NULL) == -1) { 1028*0Sstevel@tonic-gate if (errno == EBUSY) 1029*0Sstevel@tonic-gate rv = CFGA_BUSY; 1030*0Sstevel@tonic-gate else { 1031*0Sstevel@tonic-gate if (errno == ENOTSUP) 1032*0Sstevel@tonic-gate rv = CFGA_OPNOTSUPP; 1033*0Sstevel@tonic-gate else 1034*0Sstevel@tonic-gate rv = CFGA_ERROR; 1035*0Sstevel@tonic-gate } 1036*0Sstevel@tonic-gate cfga_err(errstring, 1037*0Sstevel@tonic-gate CMD_SLOT_UNCONFIGURE, 0); 1038*0Sstevel@tonic-gate } else { 1039*0Sstevel@tonic-gate rv = CFGA_OK; 1040*0Sstevel@tonic-gate } 1041*0Sstevel@tonic-gate } 1042*0Sstevel@tonic-gate } else { 1043*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, 0); 1044*0Sstevel@tonic-gate rv = CFGA_INVAL; 1045*0Sstevel@tonic-gate } 1046*0Sstevel@tonic-gate 1047*0Sstevel@tonic-gate DBG(1, ("uncofigure rv:(%i)\n", rv)); 1048*0Sstevel@tonic-gate break; 1049*0Sstevel@tonic-gate 1050*0Sstevel@tonic-gate case CFGA_CMD_LOAD: 1051*0Sstevel@tonic-gate if ((os == AP_OSTATE_UNCONFIGURED) && 1052*0Sstevel@tonic-gate (rs == AP_RSTATE_DISCONNECTED)) { 1053*0Sstevel@tonic-gate if (devctl_ap_insert(dcp, NULL) == -1) { 1054*0Sstevel@tonic-gate rv = CFGA_ERROR; 1055*0Sstevel@tonic-gate cfga_err(errstring, CMD_SLOT_INSERT, 0); 1056*0Sstevel@tonic-gate } 1057*0Sstevel@tonic-gate } else { 1058*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, 0); 1059*0Sstevel@tonic-gate rv = CFGA_INVAL; 1060*0Sstevel@tonic-gate } 1061*0Sstevel@tonic-gate 1062*0Sstevel@tonic-gate break; 1063*0Sstevel@tonic-gate 1064*0Sstevel@tonic-gate case CFGA_CMD_UNLOAD: 1065*0Sstevel@tonic-gate if ((os == AP_OSTATE_UNCONFIGURED) && 1066*0Sstevel@tonic-gate (rs == AP_RSTATE_DISCONNECTED)) { 1067*0Sstevel@tonic-gate if (devctl_ap_remove(dcp, NULL) == -1) { 1068*0Sstevel@tonic-gate rv = CFGA_ERROR; 1069*0Sstevel@tonic-gate cfga_err(errstring, CMD_SLOT_REMOVE, 0); 1070*0Sstevel@tonic-gate } 1071*0Sstevel@tonic-gate } else { 1072*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, 0); 1073*0Sstevel@tonic-gate rv = CFGA_INVAL; 1074*0Sstevel@tonic-gate } 1075*0Sstevel@tonic-gate 1076*0Sstevel@tonic-gate break; 1077*0Sstevel@tonic-gate 1078*0Sstevel@tonic-gate default: 1079*0Sstevel@tonic-gate rv = CFGA_OPNOTSUPP; 1080*0Sstevel@tonic-gate break; 1081*0Sstevel@tonic-gate } 1082*0Sstevel@tonic-gate 1083*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1084*0Sstevel@tonic-gate return (rv); 1085*0Sstevel@tonic-gate } 1086*0Sstevel@tonic-gate 1087*0Sstevel@tonic-gate /* 1088*0Sstevel@tonic-gate * Building iocdatat to pass it to nexus 1089*0Sstevel@tonic-gate * 1090*0Sstevel@tonic-gate * iocdata->cmd == HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT 1091*0Sstevel@tonic-gate * HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG 1092*0Sstevel@tonic-gate * HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE 1093*0Sstevel@tonic-gate * HPC_CTRL_GET_SLOT_STATE/HPC_CTRL_GET_SLOT_INFO 1094*0Sstevel@tonic-gate * HPC_CTRL_DEV_CONFIGURE/HPC_CTRL_DEV_UNCONFIGURE 1095*0Sstevel@tonic-gate * HPC_CTRL_GET_BOARD_TYPE 1096*0Sstevel@tonic-gate * 1097*0Sstevel@tonic-gate */ 1098*0Sstevel@tonic-gate static void 1099*0Sstevel@tonic-gate build_control_data(struct hpc_control_data *iocdata, uint_t cmd, 1100*0Sstevel@tonic-gate void *retdata) 1101*0Sstevel@tonic-gate { 1102*0Sstevel@tonic-gate iocdata->cmd = cmd; 1103*0Sstevel@tonic-gate iocdata->data = retdata; 1104*0Sstevel@tonic-gate } 1105*0Sstevel@tonic-gate 1106*0Sstevel@tonic-gate /* 1107*0Sstevel@tonic-gate * building logical name from ap_id 1108*0Sstevel@tonic-gate */ 1109*0Sstevel@tonic-gate /*ARGSUSED2*/ 1110*0Sstevel@tonic-gate static void 1111*0Sstevel@tonic-gate get_logical_name(const char *ap_id, char *buf, dev_t rdev) 1112*0Sstevel@tonic-gate { 1113*0Sstevel@tonic-gate char *bufptr, *bufptr2, *pci, *apid; 1114*0Sstevel@tonic-gate 1115*0Sstevel@tonic-gate DBG(1, ("get_logical_name: %s\n", ap_id)); 1116*0Sstevel@tonic-gate 1117*0Sstevel@tonic-gate if ((apid = malloc(MAXPATHLEN)) == NULL) { 1118*0Sstevel@tonic-gate DBG(1, ("malloc failed\n")); 1119*0Sstevel@tonic-gate return; 1120*0Sstevel@tonic-gate } 1121*0Sstevel@tonic-gate 1122*0Sstevel@tonic-gate (void) memset(apid, 0, MAXPATHLEN); 1123*0Sstevel@tonic-gate (void) strncpy(apid, ap_id, strlen(ap_id)); 1124*0Sstevel@tonic-gate 1125*0Sstevel@tonic-gate /* needs to look for last /, not first */ 1126*0Sstevel@tonic-gate bufptr = strrchr(apid, '/'); 1127*0Sstevel@tonic-gate 1128*0Sstevel@tonic-gate bufptr2 = strrchr(apid, ':'); 1129*0Sstevel@tonic-gate pci = ++bufptr; 1130*0Sstevel@tonic-gate bufptr = strchr(pci, ','); 1131*0Sstevel@tonic-gate if (bufptr != NULL) { 1132*0Sstevel@tonic-gate *bufptr = '\0'; 1133*0Sstevel@tonic-gate } 1134*0Sstevel@tonic-gate 1135*0Sstevel@tonic-gate bufptr = strchr(pci, '@'); 1136*0Sstevel@tonic-gate if (bufptr != NULL) { 1137*0Sstevel@tonic-gate *bufptr = '\0'; 1138*0Sstevel@tonic-gate bufptr++; 1139*0Sstevel@tonic-gate } 1140*0Sstevel@tonic-gate 1141*0Sstevel@tonic-gate DBG(1, ("%s\n%s\n%s\n", pci, bufptr, bufptr2)); 1142*0Sstevel@tonic-gate 1143*0Sstevel@tonic-gate (void) strcat(buf, pci); 1144*0Sstevel@tonic-gate (void) strcat(buf, bufptr); 1145*0Sstevel@tonic-gate (void) strcat(buf, bufptr2); 1146*0Sstevel@tonic-gate free(apid); 1147*0Sstevel@tonic-gate } 1148*0Sstevel@tonic-gate 1149*0Sstevel@tonic-gate static cfga_err_t 1150*0Sstevel@tonic-gate prt_led_mode(const char *ap_id, int repeat, char **errstring, 1151*0Sstevel@tonic-gate struct cfga_msg *msgp) 1152*0Sstevel@tonic-gate { 1153*0Sstevel@tonic-gate hpc_led_info_t power_led_info = {HPC_POWER_LED, 0}; 1154*0Sstevel@tonic-gate hpc_led_info_t fault_led_info = {HPC_FAULT_LED, 0}; 1155*0Sstevel@tonic-gate hpc_led_info_t attn_led_info = {HPC_ATTN_LED, 0}; 1156*0Sstevel@tonic-gate hpc_led_info_t active_led_info = {HPC_ACTIVE_LED, 0}; 1157*0Sstevel@tonic-gate struct hpc_control_data iocdata; 1158*0Sstevel@tonic-gate struct stat statbuf; 1159*0Sstevel@tonic-gate char *buff; 1160*0Sstevel@tonic-gate int fd; 1161*0Sstevel@tonic-gate hpc_slot_info_t slot_info; 1162*0Sstevel@tonic-gate char *cp, line[MAXLINE]; 1163*0Sstevel@tonic-gate int len = MAXLINE; 1164*0Sstevel@tonic-gate 1165*0Sstevel@tonic-gate DBG(1, ("prt_led_mod function\n")); 1166*0Sstevel@tonic-gate if (!repeat) 1167*0Sstevel@tonic-gate cfga_msg(msgp, "Ap_Id\t\t\tLed"); 1168*0Sstevel@tonic-gate 1169*0Sstevel@tonic-gate if ((fd = open(ap_id, O_RDWR)) == -1) { 1170*0Sstevel@tonic-gate DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd)); 1171*0Sstevel@tonic-gate DBG_F(2, (stderr, "open on %s failed\n", ap_id)); 1172*0Sstevel@tonic-gate cfga_err(errstring, CMD_OPEN, ap_id, 0); 1173*0Sstevel@tonic-gate return (CFGA_ERROR); 1174*0Sstevel@tonic-gate } 1175*0Sstevel@tonic-gate 1176*0Sstevel@tonic-gate if (fstat(fd, &statbuf) == -1) { 1177*0Sstevel@tonic-gate DBG(2, ("fstat = ap_id%s, fd%d\n", ap_id, fd)); 1178*0Sstevel@tonic-gate DBG_F(2, (stderr, "fstat on %s failed\n", ap_id)); 1179*0Sstevel@tonic-gate cfga_err(errstring, CMD_FSTAT, ap_id, 0); 1180*0Sstevel@tonic-gate return (CFGA_ERROR); 1181*0Sstevel@tonic-gate } 1182*0Sstevel@tonic-gate 1183*0Sstevel@tonic-gate if ((buff = malloc(MAXPATHLEN)) == NULL) { 1184*0Sstevel@tonic-gate cfga_err(errstring, "malloc ", 0); 1185*0Sstevel@tonic-gate return (CFGA_ERROR); 1186*0Sstevel@tonic-gate } 1187*0Sstevel@tonic-gate 1188*0Sstevel@tonic-gate (void) memset(buff, 0, MAXPATHLEN); 1189*0Sstevel@tonic-gate 1190*0Sstevel@tonic-gate DBG(1, ("ioctl boardtype\n")); 1191*0Sstevel@tonic-gate 1192*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO, 1193*0Sstevel@tonic-gate (void *)&slot_info); 1194*0Sstevel@tonic-gate 1195*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1196*0Sstevel@tonic-gate get_logical_name(ap_id, slot_info.pci_slot_name, 0); 1197*0Sstevel@tonic-gate DBG(1, ("ioctl failed slotinfo: %s\n", 1198*0Sstevel@tonic-gate slot_info.pci_slot_name)); 1199*0Sstevel@tonic-gate } else { 1200*0Sstevel@tonic-gate 1201*0Sstevel@tonic-gate /* 1202*0Sstevel@tonic-gate * the driver will report back things like hpc0_slot0 1203*0Sstevel@tonic-gate * this needs to be changed to things like pci1:hpc0_slot0 1204*0Sstevel@tonic-gate */ 1205*0Sstevel@tonic-gate if (fix_ap_name(buff, ap_id, slot_info.pci_slot_name, 1206*0Sstevel@tonic-gate errstring) != CFGA_OK) { 1207*0Sstevel@tonic-gate free(buff); 1208*0Sstevel@tonic-gate (void) close(fd); 1209*0Sstevel@tonic-gate return (CFGA_ERROR); 1210*0Sstevel@tonic-gate } 1211*0Sstevel@tonic-gate DBG(1, ("ioctl slotinfo: %s\n", buff)); 1212*0Sstevel@tonic-gate } 1213*0Sstevel@tonic-gate 1214*0Sstevel@tonic-gate cp = line; 1215*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s\t\t", buff); 1216*0Sstevel@tonic-gate len -= strlen(cp); 1217*0Sstevel@tonic-gate cp += strlen(cp); 1218*0Sstevel@tonic-gate 1219*0Sstevel@tonic-gate free(buff); 1220*0Sstevel@tonic-gate 1221*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &power_led_info); 1222*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1223*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", 1224*0Sstevel@tonic-gate led_strs[power_led_info.led], cfga_strs[UNKNOWN]); 1225*0Sstevel@tonic-gate len -= strlen(cp); 1226*0Sstevel@tonic-gate cp += strlen(cp); 1227*0Sstevel@tonic-gate } else { 1228*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", led_strs[power_led_info.led], 1229*0Sstevel@tonic-gate mode_strs[power_led_info.state]); 1230*0Sstevel@tonic-gate len -= strlen(cp); 1231*0Sstevel@tonic-gate cp += strlen(cp); 1232*0Sstevel@tonic-gate } 1233*0Sstevel@tonic-gate 1234*0Sstevel@tonic-gate DBG(1, ("%s:%d\n", led_strs[power_led_info.led], power_led_info.state)); 1235*0Sstevel@tonic-gate 1236*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &fault_led_info); 1237*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1238*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", 1239*0Sstevel@tonic-gate led_strs[fault_led_info.led], cfga_strs[UNKNOWN]); 1240*0Sstevel@tonic-gate len -= strlen(cp); 1241*0Sstevel@tonic-gate cp += strlen(cp); 1242*0Sstevel@tonic-gate } else { 1243*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", 1244*0Sstevel@tonic-gate led_strs[fault_led_info.led], 1245*0Sstevel@tonic-gate mode_strs[fault_led_info.state]); 1246*0Sstevel@tonic-gate len -= strlen(cp); 1247*0Sstevel@tonic-gate cp += strlen(cp); 1248*0Sstevel@tonic-gate } 1249*0Sstevel@tonic-gate DBG(1, ("%s:%d\n", led_strs[fault_led_info.led], fault_led_info.state)); 1250*0Sstevel@tonic-gate 1251*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &attn_led_info); 1252*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1253*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", 1254*0Sstevel@tonic-gate led_strs[attn_led_info.led], cfga_strs[UNKNOWN]); 1255*0Sstevel@tonic-gate len -= strlen(cp); 1256*0Sstevel@tonic-gate cp += strlen(cp); 1257*0Sstevel@tonic-gate } else { 1258*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s,", 1259*0Sstevel@tonic-gate led_strs[attn_led_info.led], 1260*0Sstevel@tonic-gate mode_strs[attn_led_info.state]); 1261*0Sstevel@tonic-gate len -= strlen(cp); 1262*0Sstevel@tonic-gate cp += strlen(cp); 1263*0Sstevel@tonic-gate } 1264*0Sstevel@tonic-gate DBG(1, ("%s:%d\n", led_strs[attn_led_info.led], attn_led_info.state)); 1265*0Sstevel@tonic-gate 1266*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &active_led_info); 1267*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1268*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s", led_strs[active_led_info.led], 1269*0Sstevel@tonic-gate cfga_strs[UNKNOWN]); 1270*0Sstevel@tonic-gate } else { 1271*0Sstevel@tonic-gate (void) snprintf(cp, len, "%s=%s", 1272*0Sstevel@tonic-gate led_strs[active_led_info.led], 1273*0Sstevel@tonic-gate mode_strs[active_led_info.state]); 1274*0Sstevel@tonic-gate } 1275*0Sstevel@tonic-gate cfga_msg(msgp, line); /* print the message */ 1276*0Sstevel@tonic-gate DBG(1, ("%s:%d\n", led_strs[active_led_info.led], 1277*0Sstevel@tonic-gate active_led_info.state)); 1278*0Sstevel@tonic-gate 1279*0Sstevel@tonic-gate (void) close(fd); 1280*0Sstevel@tonic-gate 1281*0Sstevel@tonic-gate return (CFGA_OK); 1282*0Sstevel@tonic-gate } 1283*0Sstevel@tonic-gate 1284*0Sstevel@tonic-gate /*ARGSUSED*/ 1285*0Sstevel@tonic-gate cfga_err_t 1286*0Sstevel@tonic-gate cfga_private_func(const char *function, const char *ap_id, 1287*0Sstevel@tonic-gate const char *options, struct cfga_confirm *confp, 1288*0Sstevel@tonic-gate struct cfga_msg *msgp, char **errstring, cfga_flags_t flags) 1289*0Sstevel@tonic-gate { 1290*0Sstevel@tonic-gate char *str; 1291*0Sstevel@tonic-gate int len, fd, i = 0, repeat = 0; 1292*0Sstevel@tonic-gate char buf[MAXNAMELEN]; 1293*0Sstevel@tonic-gate char ptr; 1294*0Sstevel@tonic-gate hpc_led_info_t led_info; 1295*0Sstevel@tonic-gate struct hpc_control_data iocdata; 1296*0Sstevel@tonic-gate cfga_err_t rv; 1297*0Sstevel@tonic-gate 1298*0Sstevel@tonic-gate DBG(1, ("cfgadm_private_func: ap_id:%s\n", ap_id)); 1299*0Sstevel@tonic-gate DBG(2, (" options: %s\n", (options == NULL)?"null":options)); 1300*0Sstevel@tonic-gate DBG(2, (" confp: %x\n", confp)); 1301*0Sstevel@tonic-gate DBG(2, (" cfga_msg: %x\n", cfga_msg)); 1302*0Sstevel@tonic-gate DBG(2, (" flag: %d\n", flags)); 1303*0Sstevel@tonic-gate 1304*0Sstevel@tonic-gate if ((rv = check_options(options)) != CFGA_OK) { 1305*0Sstevel@tonic-gate return (rv); 1306*0Sstevel@tonic-gate } 1307*0Sstevel@tonic-gate 1308*0Sstevel@tonic-gate if (private_check == confp) 1309*0Sstevel@tonic-gate repeat = 1; 1310*0Sstevel@tonic-gate else 1311*0Sstevel@tonic-gate private_check = (void*)confp; 1312*0Sstevel@tonic-gate 1313*0Sstevel@tonic-gate /* XXX change const 6 to func_str[i] != NULL */ 1314*0Sstevel@tonic-gate for (i = 0, str = func_strs[i], len = strlen(str); i < 6; i++) { 1315*0Sstevel@tonic-gate str = func_strs[i]; 1316*0Sstevel@tonic-gate len = strlen(str); 1317*0Sstevel@tonic-gate if (strncmp(function, str, len) == 0) 1318*0Sstevel@tonic-gate break; 1319*0Sstevel@tonic-gate } 1320*0Sstevel@tonic-gate 1321*0Sstevel@tonic-gate switch (i) { 1322*0Sstevel@tonic-gate case ENABLE_SLOT: 1323*0Sstevel@tonic-gate build_control_data(&iocdata, 1324*0Sstevel@tonic-gate HPC_CTRL_ENABLE_SLOT, 0); 1325*0Sstevel@tonic-gate break; 1326*0Sstevel@tonic-gate case DISABLE_SLOT: 1327*0Sstevel@tonic-gate build_control_data(&iocdata, 1328*0Sstevel@tonic-gate HPC_CTRL_DISABLE_SLOT, 0); 1329*0Sstevel@tonic-gate break; 1330*0Sstevel@tonic-gate case ENABLE_AUTOCNF: 1331*0Sstevel@tonic-gate build_control_data(&iocdata, 1332*0Sstevel@tonic-gate HPC_CTRL_ENABLE_AUTOCFG, 0); 1333*0Sstevel@tonic-gate break; 1334*0Sstevel@tonic-gate case DISABLE_AUTOCNF: 1335*0Sstevel@tonic-gate build_control_data(&iocdata, 1336*0Sstevel@tonic-gate HPC_CTRL_DISABLE_AUTOCFG, 0); 1337*0Sstevel@tonic-gate break; 1338*0Sstevel@tonic-gate case LED: 1339*0Sstevel@tonic-gate /* set mode */ 1340*0Sstevel@tonic-gate ptr = function[len++]; 1341*0Sstevel@tonic-gate if (ptr == '=') { 1342*0Sstevel@tonic-gate str = (char *)function; 1343*0Sstevel@tonic-gate for (str = (str+len++), i = 0; *str != ','; 1344*0Sstevel@tonic-gate i++, str++) { 1345*0Sstevel@tonic-gate if (i == (MAXNAMELEN - 1)) 1346*0Sstevel@tonic-gate break; 1347*0Sstevel@tonic-gate 1348*0Sstevel@tonic-gate buf[i] = *str; 1349*0Sstevel@tonic-gate DBG_F(2, (stdout, "%c\n", buf[i])); 1350*0Sstevel@tonic-gate } 1351*0Sstevel@tonic-gate buf[i] = '\0'; str++; 1352*0Sstevel@tonic-gate DBG(2, ("buf = %s\n", buf)); 1353*0Sstevel@tonic-gate 1354*0Sstevel@tonic-gate /* ACTIVE=3,ATTN=2,POWER=1,FAULT=0 */ 1355*0Sstevel@tonic-gate if (strcmp(buf, led_strs[POWER]) == 0) 1356*0Sstevel@tonic-gate led_info.led = HPC_POWER_LED; 1357*0Sstevel@tonic-gate else if (strcmp(buf, led_strs[FAULT]) == 0) 1358*0Sstevel@tonic-gate led_info.led = HPC_FAULT_LED; 1359*0Sstevel@tonic-gate else if (strcmp(buf, led_strs[ATTN]) == 0) 1360*0Sstevel@tonic-gate led_info.led = HPC_ATTN_LED; 1361*0Sstevel@tonic-gate else if (strcmp(buf, led_strs[ACTIVE]) == 0) 1362*0Sstevel@tonic-gate led_info.led = HPC_ACTIVE_LED; 1363*0Sstevel@tonic-gate else return (CFGA_INVAL); 1364*0Sstevel@tonic-gate 1365*0Sstevel@tonic-gate len = strlen(func_strs[MODE]); 1366*0Sstevel@tonic-gate if ((strncmp(str, func_strs[MODE], len) == 0) && 1367*0Sstevel@tonic-gate (*(str+(len)) == '=')) { 1368*0Sstevel@tonic-gate for (str = (str+(++len)), i = 0; 1369*0Sstevel@tonic-gate *str != NULL; i++, str++) { 1370*0Sstevel@tonic-gate buf[i] = *str; 1371*0Sstevel@tonic-gate 1372*0Sstevel@tonic-gate } 1373*0Sstevel@tonic-gate } 1374*0Sstevel@tonic-gate buf[i] = '\0'; 1375*0Sstevel@tonic-gate DBG(2, ("buf_mode= %s\n", buf)); 1376*0Sstevel@tonic-gate 1377*0Sstevel@tonic-gate /* ON = 1, OFF = 0 */ 1378*0Sstevel@tonic-gate if (strcmp(buf, mode_strs[ON]) == 0) 1379*0Sstevel@tonic-gate led_info.state = HPC_LED_ON; 1380*0Sstevel@tonic-gate else if (strcmp(buf, mode_strs[OFF]) == 0) 1381*0Sstevel@tonic-gate led_info.state = HPC_LED_OFF; 1382*0Sstevel@tonic-gate else if (strcmp(buf, mode_strs[BLINK]) == 0) 1383*0Sstevel@tonic-gate led_info.state = HPC_LED_BLINK; 1384*0Sstevel@tonic-gate else return (CFGA_INVAL); 1385*0Sstevel@tonic-gate 1386*0Sstevel@tonic-gate /* sendin */ 1387*0Sstevel@tonic-gate build_control_data(&iocdata, 1388*0Sstevel@tonic-gate HPC_CTRL_SET_LED_STATE, 1389*0Sstevel@tonic-gate (void *)&led_info); 1390*0Sstevel@tonic-gate break; 1391*0Sstevel@tonic-gate } else if (ptr == '\0') { 1392*0Sstevel@tonic-gate /* print mode */ 1393*0Sstevel@tonic-gate DBG(1, ("Print mode\n")); 1394*0Sstevel@tonic-gate return (prt_led_mode(ap_id, repeat, errstring, 1395*0Sstevel@tonic-gate msgp)); 1396*0Sstevel@tonic-gate } 1397*0Sstevel@tonic-gate default: 1398*0Sstevel@tonic-gate DBG(1, ("default\n")); 1399*0Sstevel@tonic-gate errno = EINVAL; 1400*0Sstevel@tonic-gate return (CFGA_INVAL); 1401*0Sstevel@tonic-gate } 1402*0Sstevel@tonic-gate 1403*0Sstevel@tonic-gate if ((fd = open(ap_id, O_RDWR)) == -1) { 1404*0Sstevel@tonic-gate DBG(1, ("open failed\n")); 1405*0Sstevel@tonic-gate return (CFGA_ERROR); 1406*0Sstevel@tonic-gate } 1407*0Sstevel@tonic-gate 1408*0Sstevel@tonic-gate DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd)); 1409*0Sstevel@tonic-gate 1410*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1411*0Sstevel@tonic-gate DBG(1, ("ioctl failed\n")); 1412*0Sstevel@tonic-gate (void) close(fd); 1413*0Sstevel@tonic-gate return (CFGA_ERROR); 1414*0Sstevel@tonic-gate } 1415*0Sstevel@tonic-gate 1416*0Sstevel@tonic-gate (void) close(fd); 1417*0Sstevel@tonic-gate 1418*0Sstevel@tonic-gate return (CFGA_OK); 1419*0Sstevel@tonic-gate } 1420*0Sstevel@tonic-gate 1421*0Sstevel@tonic-gate /*ARGSUSED*/ 1422*0Sstevel@tonic-gate cfga_err_t cfga_test(const char *ap_id, const char *options, 1423*0Sstevel@tonic-gate struct cfga_msg *msgp, char **errstring, cfga_flags_t flags) 1424*0Sstevel@tonic-gate { 1425*0Sstevel@tonic-gate cfga_err_t rv; 1426*0Sstevel@tonic-gate if (errstring != NULL) 1427*0Sstevel@tonic-gate *errstring = NULL; 1428*0Sstevel@tonic-gate 1429*0Sstevel@tonic-gate if ((rv = check_options(options)) != CFGA_OK) { 1430*0Sstevel@tonic-gate return (rv); 1431*0Sstevel@tonic-gate } 1432*0Sstevel@tonic-gate 1433*0Sstevel@tonic-gate DBG(1, ("cfga_test:(%s)\n", ap_id)); 1434*0Sstevel@tonic-gate /* will need to implement pci CTRL command */ 1435*0Sstevel@tonic-gate return (CFGA_NOTSUPP); 1436*0Sstevel@tonic-gate } 1437*0Sstevel@tonic-gate 1438*0Sstevel@tonic-gate static int 1439*0Sstevel@tonic-gate fixup_slotname(int rval, int *intp, struct searcharg *slotarg) 1440*0Sstevel@tonic-gate { 1441*0Sstevel@tonic-gate 1442*0Sstevel@tonic-gate /* 1443*0Sstevel@tonic-gate * The slot-names property describes the external labeling of add-in slots. 1444*0Sstevel@tonic-gate * This property is an encoded array, an integer followed by a list of 1445*0Sstevel@tonic-gate * strings. The return value from di_prop_lookup_ints for slot-names is -1. 1446*0Sstevel@tonic-gate * The expected return value should be the number of elements. 1447*0Sstevel@tonic-gate * Di_prop_decode_common does not decode encoded data from software, 1448*0Sstevel@tonic-gate * such as the solaris device tree, unlike from the prom. 1449*0Sstevel@tonic-gate * Di_prop_decode_common takes the size of the encoded data and mods 1450*0Sstevel@tonic-gate * it with the size of int. The size of the encoded data for slot-names is 9 1451*0Sstevel@tonic-gate * and the size of int is 4, yielding a non zero result. A value of -1 is used 1452*0Sstevel@tonic-gate * to indicate that the number of elements can not be determined. 1453*0Sstevel@tonic-gate * Di_prop_decode_common can be modified to decode encoded data from the solaris 1454*0Sstevel@tonic-gate * device tree. 1455*0Sstevel@tonic-gate */ 1456*0Sstevel@tonic-gate 1457*0Sstevel@tonic-gate if ((slotarg->slt_name_src == PROM_SLT_NAME) && (rval == -1)) { 1458*0Sstevel@tonic-gate return (DI_WALK_TERMINATE); 1459*0Sstevel@tonic-gate } else { 1460*0Sstevel@tonic-gate int i; 1461*0Sstevel@tonic-gate char *tmptr = (char *)(intp+1); 1462*0Sstevel@tonic-gate DBG(1, ("slot-bitmask: %x \n", *intp)); 1463*0Sstevel@tonic-gate 1464*0Sstevel@tonic-gate rval = (rval -1) * 4; 1465*0Sstevel@tonic-gate 1466*0Sstevel@tonic-gate for (i = 0; i <= slotarg->minor; i++) { 1467*0Sstevel@tonic-gate DBG(2, ("curr slot-name: %s \n", tmptr)); 1468*0Sstevel@tonic-gate 1469*0Sstevel@tonic-gate if (i >= MAXDEVS) 1470*0Sstevel@tonic-gate return (DI_WALK_TERMINATE); 1471*0Sstevel@tonic-gate 1472*0Sstevel@tonic-gate if ((*intp >> i) & 1) { 1473*0Sstevel@tonic-gate /* assign tmptr */ 1474*0Sstevel@tonic-gate DBG(2, ("slot-name: %s \n", tmptr)); 1475*0Sstevel@tonic-gate if (i == slotarg->minor) 1476*0Sstevel@tonic-gate (void) strcpy(slotarg->slotnames[i], 1477*0Sstevel@tonic-gate tmptr); 1478*0Sstevel@tonic-gate /* wind tmptr to next \0 */ 1479*0Sstevel@tonic-gate while (*tmptr != '\0') { 1480*0Sstevel@tonic-gate tmptr++; 1481*0Sstevel@tonic-gate } 1482*0Sstevel@tonic-gate tmptr++; 1483*0Sstevel@tonic-gate } else { 1484*0Sstevel@tonic-gate /* point at unknown string */ 1485*0Sstevel@tonic-gate if (i == slotarg->minor) 1486*0Sstevel@tonic-gate (void) strcpy(slotarg->slotnames[i], 1487*0Sstevel@tonic-gate "unknown"); 1488*0Sstevel@tonic-gate } 1489*0Sstevel@tonic-gate } 1490*0Sstevel@tonic-gate } 1491*0Sstevel@tonic-gate return (DI_WALK_TERMINATE); 1492*0Sstevel@tonic-gate } 1493*0Sstevel@tonic-gate 1494*0Sstevel@tonic-gate static int 1495*0Sstevel@tonic-gate find_slotname(di_node_t din, di_minor_t dim, void *arg) 1496*0Sstevel@tonic-gate { 1497*0Sstevel@tonic-gate struct searcharg *slotarg = (struct searcharg *)arg; 1498*0Sstevel@tonic-gate di_prom_handle_t ph = (di_prom_handle_t)slotarg->promp; 1499*0Sstevel@tonic-gate di_prom_prop_t prom_prop; 1500*0Sstevel@tonic-gate di_prop_t solaris_prop; 1501*0Sstevel@tonic-gate int *intp, rval; 1502*0Sstevel@tonic-gate char *devname; 1503*0Sstevel@tonic-gate char fulldevname[MAXNAMELEN]; 1504*0Sstevel@tonic-gate 1505*0Sstevel@tonic-gate slotarg->minor = dim->dev_minor % 256; 1506*0Sstevel@tonic-gate 1507*0Sstevel@tonic-gate DBG(2, ("minor number:(%i)\n", slotarg->minor)); 1508*0Sstevel@tonic-gate DBG(2, ("hot plug slots found so far:(%i)\n", 0)); 1509*0Sstevel@tonic-gate 1510*0Sstevel@tonic-gate if ((devname = di_devfs_path(din)) != NULL) { 1511*0Sstevel@tonic-gate (void) snprintf(fulldevname, MAXNAMELEN, 1512*0Sstevel@tonic-gate "/devices%s:%s", devname, di_minor_name(dim)); 1513*0Sstevel@tonic-gate di_devfs_path_free(devname); 1514*0Sstevel@tonic-gate } 1515*0Sstevel@tonic-gate 1516*0Sstevel@tonic-gate if (strcmp(fulldevname, slotarg->devpath) == 0) { 1517*0Sstevel@tonic-gate 1518*0Sstevel@tonic-gate /* 1519*0Sstevel@tonic-gate * Check the Solaris device tree first 1520*0Sstevel@tonic-gate * in the case of a DR operation 1521*0Sstevel@tonic-gate */ 1522*0Sstevel@tonic-gate solaris_prop = di_prop_hw_next(din, DI_PROP_NIL); 1523*0Sstevel@tonic-gate while (solaris_prop != DI_PROP_NIL) { 1524*0Sstevel@tonic-gate if (strcmp("slot-names", di_prop_name(solaris_prop)) 1525*0Sstevel@tonic-gate == 0) { 1526*0Sstevel@tonic-gate rval = di_prop_lookup_ints(DDI_DEV_T_ANY, 1527*0Sstevel@tonic-gate din, di_prop_name(solaris_prop), &intp); 1528*0Sstevel@tonic-gate slotarg->slt_name_src = SOLARIS_SLT_NAME; 1529*0Sstevel@tonic-gate 1530*0Sstevel@tonic-gate return (fixup_slotname(rval, intp, slotarg)); 1531*0Sstevel@tonic-gate } 1532*0Sstevel@tonic-gate solaris_prop = di_prop_hw_next(din, solaris_prop); 1533*0Sstevel@tonic-gate } 1534*0Sstevel@tonic-gate 1535*0Sstevel@tonic-gate /* 1536*0Sstevel@tonic-gate * Check the prom device tree which is populated at boot. 1537*0Sstevel@tonic-gate * If this fails, give up and set the slot name to null. 1538*0Sstevel@tonic-gate */ 1539*0Sstevel@tonic-gate prom_prop = di_prom_prop_next(ph, din, DI_PROM_PROP_NIL); 1540*0Sstevel@tonic-gate while (prom_prop != DI_PROM_PROP_NIL) { 1541*0Sstevel@tonic-gate if (strcmp("slot-names", di_prom_prop_name(prom_prop)) 1542*0Sstevel@tonic-gate == 0) { 1543*0Sstevel@tonic-gate rval = di_prom_prop_lookup_ints(ph, 1544*0Sstevel@tonic-gate din, di_prom_prop_name(prom_prop), &intp); 1545*0Sstevel@tonic-gate slotarg->slt_name_src = PROM_SLT_NAME; 1546*0Sstevel@tonic-gate 1547*0Sstevel@tonic-gate return (fixup_slotname(rval, intp, slotarg)); 1548*0Sstevel@tonic-gate } 1549*0Sstevel@tonic-gate prom_prop = di_prom_prop_next(ph, din, prom_prop); 1550*0Sstevel@tonic-gate } 1551*0Sstevel@tonic-gate *slotarg->slotnames[slotarg->minor] = '\0'; 1552*0Sstevel@tonic-gate return (DI_WALK_TERMINATE); 1553*0Sstevel@tonic-gate } else 1554*0Sstevel@tonic-gate return (DI_WALK_CONTINUE); 1555*0Sstevel@tonic-gate } 1556*0Sstevel@tonic-gate 1557*0Sstevel@tonic-gate static int 1558*0Sstevel@tonic-gate find_physical_slot_names(const char *devcomp, struct searcharg *slotarg) 1559*0Sstevel@tonic-gate { 1560*0Sstevel@tonic-gate di_node_t root_node; 1561*0Sstevel@tonic-gate 1562*0Sstevel@tonic-gate DBG(1, ("find_physical_slot_names\n")); 1563*0Sstevel@tonic-gate 1564*0Sstevel@tonic-gate if ((root_node = di_init("/", DINFOCPYALL|DINFOPATH)) 1565*0Sstevel@tonic-gate == DI_NODE_NIL) { 1566*0Sstevel@tonic-gate DBG(1, ("di_init() failed\n")); 1567*0Sstevel@tonic-gate return (NULL); 1568*0Sstevel@tonic-gate } 1569*0Sstevel@tonic-gate 1570*0Sstevel@tonic-gate slotarg->devpath = (char *)devcomp; 1571*0Sstevel@tonic-gate 1572*0Sstevel@tonic-gate if ((slotarg->promp = di_prom_init()) == DI_PROM_HANDLE_NIL) { 1573*0Sstevel@tonic-gate DBG(1, ("di_prom_init() failed\n")); 1574*0Sstevel@tonic-gate di_fini(root_node); 1575*0Sstevel@tonic-gate return (NULL); 1576*0Sstevel@tonic-gate } 1577*0Sstevel@tonic-gate 1578*0Sstevel@tonic-gate (void) di_walk_minor(root_node, "ddi_ctl:attachment_point:pci", 1579*0Sstevel@tonic-gate 0, (void *)slotarg, find_slotname); 1580*0Sstevel@tonic-gate 1581*0Sstevel@tonic-gate di_prom_fini(slotarg->promp); 1582*0Sstevel@tonic-gate di_fini(root_node); 1583*0Sstevel@tonic-gate if (slotarg->slotnames[0] != NULL) 1584*0Sstevel@tonic-gate return (0); 1585*0Sstevel@tonic-gate else 1586*0Sstevel@tonic-gate return (-1); 1587*0Sstevel@tonic-gate } 1588*0Sstevel@tonic-gate 1589*0Sstevel@tonic-gate static void 1590*0Sstevel@tonic-gate get_type(hpc_board_type_t boardtype, hpc_card_info_t cardinfo, char *buf) 1591*0Sstevel@tonic-gate { 1592*0Sstevel@tonic-gate 1593*0Sstevel@tonic-gate DBG(1, ("class: %i\n", cardinfo.base_class)); 1594*0Sstevel@tonic-gate DBG(1, ("subclass: %i\n", cardinfo.sub_class)); 1595*0Sstevel@tonic-gate 1596*0Sstevel@tonic-gate if (cardinfo.base_class == PCI_CLASS_NONE) { 1597*0Sstevel@tonic-gate TPCT("unknown"); 1598*0Sstevel@tonic-gate return; 1599*0Sstevel@tonic-gate } 1600*0Sstevel@tonic-gate 1601*0Sstevel@tonic-gate if (cardinfo.sub_class == PCISO_SUBCLASS_OTHER) { 1602*0Sstevel@tonic-gate if (cardinfo.base_class < PCISO_MAX_SUBCLASS) 1603*0Sstevel@tonic-gate TPCT(other_strs[cardinfo.base_class]); 1604*0Sstevel@tonic-gate else 1605*0Sstevel@tonic-gate TPCT("unknown"); 1606*0Sstevel@tonic-gate } else { 1607*0Sstevel@tonic-gate if (cardinfo.sub_class > PCISO_MAX_SUBCLASS) { 1608*0Sstevel@tonic-gate TPCT("unknown"); 1609*0Sstevel@tonic-gate } else { 1610*0Sstevel@tonic-gate if (cardinfo.header_type != PCI_HEADER_MULTI) { 1611*0Sstevel@tonic-gate switch (cardinfo.base_class) { 1612*0Sstevel@tonic-gate case PCI_CLASS_MASS: 1613*0Sstevel@tonic-gate TPCT(pci_masstrg[cardinfo.sub_class]); 1614*0Sstevel@tonic-gate break; 1615*0Sstevel@tonic-gate case PCI_CLASS_NET: 1616*0Sstevel@tonic-gate TPCT(pci_network[cardinfo.sub_class]); 1617*0Sstevel@tonic-gate break; 1618*0Sstevel@tonic-gate case PCI_CLASS_DISPLAY: 1619*0Sstevel@tonic-gate TPCT(pci_display[cardinfo.sub_class]); 1620*0Sstevel@tonic-gate break; 1621*0Sstevel@tonic-gate case PCI_CLASS_MM: 1622*0Sstevel@tonic-gate TPCT(pci_multimd[cardinfo.sub_class]); 1623*0Sstevel@tonic-gate break; 1624*0Sstevel@tonic-gate case PCI_CLASS_MEM: 1625*0Sstevel@tonic-gate TPCT(pci_memory[cardinfo.sub_class]); 1626*0Sstevel@tonic-gate break; 1627*0Sstevel@tonic-gate case PCI_CLASS_BRIDGE: 1628*0Sstevel@tonic-gate TPCT(pci_bridge[cardinfo.sub_class]); 1629*0Sstevel@tonic-gate break; 1630*0Sstevel@tonic-gate case PCI_CLASS_COMM: 1631*0Sstevel@tonic-gate TPCT(pci_comm[cardinfo.sub_class]); 1632*0Sstevel@tonic-gate break; 1633*0Sstevel@tonic-gate case PCI_CLASS_PERIPH: 1634*0Sstevel@tonic-gate TPCT(pci_periph[cardinfo.sub_class]); 1635*0Sstevel@tonic-gate break; 1636*0Sstevel@tonic-gate case PCI_CLASS_INPUT: 1637*0Sstevel@tonic-gate TPCT(pci_input[cardinfo.sub_class]); 1638*0Sstevel@tonic-gate break; 1639*0Sstevel@tonic-gate case PCI_CLASS_DOCK: 1640*0Sstevel@tonic-gate TPCT(pci_dock[cardinfo.sub_class]); 1641*0Sstevel@tonic-gate break; 1642*0Sstevel@tonic-gate case PCI_CLASS_PROCESSOR: 1643*0Sstevel@tonic-gate TPCT(pci_processor[cardinfo.sub_class]); 1644*0Sstevel@tonic-gate break; 1645*0Sstevel@tonic-gate case PCI_CLASS_SERIALBUS: 1646*0Sstevel@tonic-gate TPCT(pci_serial[cardinfo.sub_class]); 1647*0Sstevel@tonic-gate break; 1648*0Sstevel@tonic-gate case PCI_CLASS_WIRELESS: 1649*0Sstevel@tonic-gate TPCT(pci_wireless[cardinfo.sub_class]); 1650*0Sstevel@tonic-gate break; 1651*0Sstevel@tonic-gate case PCI_CLASS_INTIO: 1652*0Sstevel@tonic-gate TPCT(pci_intio[cardinfo.sub_class]); 1653*0Sstevel@tonic-gate break; 1654*0Sstevel@tonic-gate case PCI_CLASS_SATELLITE: 1655*0Sstevel@tonic-gate TPCT(pci_satellite[cardinfo.sub_class]); 1656*0Sstevel@tonic-gate break; 1657*0Sstevel@tonic-gate case PCI_CLASS_CRYPT: 1658*0Sstevel@tonic-gate TPCT(pci_crypt[cardinfo.sub_class]); 1659*0Sstevel@tonic-gate break; 1660*0Sstevel@tonic-gate case PCI_CLASS_SIGNAL: 1661*0Sstevel@tonic-gate TPCT(pci_signal[cardinfo.sub_class]); 1662*0Sstevel@tonic-gate break; 1663*0Sstevel@tonic-gate case PCI_CLASS_NONE: 1664*0Sstevel@tonic-gate default: 1665*0Sstevel@tonic-gate TPCT("unknown"); 1666*0Sstevel@tonic-gate return; 1667*0Sstevel@tonic-gate } 1668*0Sstevel@tonic-gate } else 1669*0Sstevel@tonic-gate TPCT("mult"); 1670*0Sstevel@tonic-gate } 1671*0Sstevel@tonic-gate } 1672*0Sstevel@tonic-gate 1673*0Sstevel@tonic-gate TPCT("/"); 1674*0Sstevel@tonic-gate switch (boardtype) { 1675*0Sstevel@tonic-gate case HPC_BOARD_PCI_HOTPLUG: 1676*0Sstevel@tonic-gate case HPC_BOARD_CPCI_NON_HS: 1677*0Sstevel@tonic-gate case HPC_BOARD_CPCI_BASIC_HS: 1678*0Sstevel@tonic-gate case HPC_BOARD_CPCI_FULL_HS: 1679*0Sstevel@tonic-gate case HPC_BOARD_CPCI_HS: 1680*0Sstevel@tonic-gate TPCT(board_strs[boardtype]); 1681*0Sstevel@tonic-gate break; 1682*0Sstevel@tonic-gate case HPC_BOARD_UNKNOWN: 1683*0Sstevel@tonic-gate default: 1684*0Sstevel@tonic-gate TPCT(board_strs[HPC_BOARD_UNKNOWN]); 1685*0Sstevel@tonic-gate } 1686*0Sstevel@tonic-gate } 1687*0Sstevel@tonic-gate 1688*0Sstevel@tonic-gate /* 1689*0Sstevel@tonic-gate * call-back function for di_devlink_walk 1690*0Sstevel@tonic-gate * if the link lives in /dev/cfg copy its name 1691*0Sstevel@tonic-gate */ 1692*0Sstevel@tonic-gate static int 1693*0Sstevel@tonic-gate found_devlink(di_devlink_t link, void *ap_log_id) 1694*0Sstevel@tonic-gate { 1695*0Sstevel@tonic-gate if (strncmp("/dev/cfg/", di_devlink_path(link), 9) == 0) { 1696*0Sstevel@tonic-gate /* copy everything but /dev/cfg/ */ 1697*0Sstevel@tonic-gate (void) strcpy((char *)ap_log_id, di_devlink_path(link) + 9); 1698*0Sstevel@tonic-gate DBG(1, ("found_devlink: %s\n", (char *)ap_log_id)); 1699*0Sstevel@tonic-gate return (DI_WALK_TERMINATE); 1700*0Sstevel@tonic-gate } 1701*0Sstevel@tonic-gate return (DI_WALK_CONTINUE); 1702*0Sstevel@tonic-gate } 1703*0Sstevel@tonic-gate 1704*0Sstevel@tonic-gate /* 1705*0Sstevel@tonic-gate * Walk throught the cached /dev link tree looking for links to the ap 1706*0Sstevel@tonic-gate * if none are found return an error 1707*0Sstevel@tonic-gate */ 1708*0Sstevel@tonic-gate static cfga_err_t 1709*0Sstevel@tonic-gate check_devlinks(char *ap_log_id, const char *ap_id) 1710*0Sstevel@tonic-gate { 1711*0Sstevel@tonic-gate di_devlink_handle_t hdl; 1712*0Sstevel@tonic-gate 1713*0Sstevel@tonic-gate DBG(1, ("check_devlinks: %s\n", ap_id)); 1714*0Sstevel@tonic-gate 1715*0Sstevel@tonic-gate hdl = di_devlink_init(NULL, 0); 1716*0Sstevel@tonic-gate 1717*0Sstevel@tonic-gate if (strncmp("/devices/", ap_id, 9) == 0) { 1718*0Sstevel@tonic-gate /* ap_id is a valid minor_path with /devices prepended */ 1719*0Sstevel@tonic-gate (void) di_devlink_walk(hdl, NULL, ap_id + 8, DI_PRIMARY_LINK, 1720*0Sstevel@tonic-gate (void *)ap_log_id, found_devlink); 1721*0Sstevel@tonic-gate } else { 1722*0Sstevel@tonic-gate DBG(1, ("check_devlinks: invalid ap_id: %s\n", ap_id)); 1723*0Sstevel@tonic-gate return (CFGA_ERROR); 1724*0Sstevel@tonic-gate } 1725*0Sstevel@tonic-gate 1726*0Sstevel@tonic-gate (void) di_devlink_fini(&hdl); 1727*0Sstevel@tonic-gate 1728*0Sstevel@tonic-gate if (ap_log_id[0] != '\0') 1729*0Sstevel@tonic-gate return (CFGA_OK); 1730*0Sstevel@tonic-gate else 1731*0Sstevel@tonic-gate return (CFGA_ERROR); 1732*0Sstevel@tonic-gate } 1733*0Sstevel@tonic-gate 1734*0Sstevel@tonic-gate /* 1735*0Sstevel@tonic-gate * most of this is needed to compensate for 1736*0Sstevel@tonic-gate * differences between various platforms 1737*0Sstevel@tonic-gate */ 1738*0Sstevel@tonic-gate static cfga_err_t 1739*0Sstevel@tonic-gate fix_ap_name(char *ap_log_id, const char *ap_id, char *slot_name, 1740*0Sstevel@tonic-gate char **errstring) 1741*0Sstevel@tonic-gate { 1742*0Sstevel@tonic-gate char *buf; 1743*0Sstevel@tonic-gate char *tmp; 1744*0Sstevel@tonic-gate char *ptr; 1745*0Sstevel@tonic-gate 1746*0Sstevel@tonic-gate di_node_t ap_node; 1747*0Sstevel@tonic-gate 1748*0Sstevel@tonic-gate ap_log_id[0] = '\0'; 1749*0Sstevel@tonic-gate 1750*0Sstevel@tonic-gate if (check_devlinks(ap_log_id, ap_id) == CFGA_OK) 1751*0Sstevel@tonic-gate return (CFGA_OK); 1752*0Sstevel@tonic-gate 1753*0Sstevel@tonic-gate DBG(1, ("fix_ap_name: %s\n", ap_id)); 1754*0Sstevel@tonic-gate 1755*0Sstevel@tonic-gate if ((buf = malloc(strlen(ap_id) + 1)) == NULL) { 1756*0Sstevel@tonic-gate DBG(1, ("malloc failed\n")); 1757*0Sstevel@tonic-gate return (CFGA_ERROR); 1758*0Sstevel@tonic-gate } 1759*0Sstevel@tonic-gate (void) strcpy(buf, ap_id); 1760*0Sstevel@tonic-gate tmp = buf + sizeof ("/devices") - 1; 1761*0Sstevel@tonic-gate 1762*0Sstevel@tonic-gate ptr = strchr(tmp, ':'); 1763*0Sstevel@tonic-gate ptr[0] = '\0'; 1764*0Sstevel@tonic-gate 1765*0Sstevel@tonic-gate DBG(1, ("fix_ap_name: %s\n", tmp)); 1766*0Sstevel@tonic-gate 1767*0Sstevel@tonic-gate ap_node = di_init(tmp, DINFOMINOR); 1768*0Sstevel@tonic-gate if (ap_node == DI_NODE_NIL) { 1769*0Sstevel@tonic-gate cfga_err(errstring, "di_init ", 0); 1770*0Sstevel@tonic-gate DBG(1, ("fix_ap_name: failed to snapshot node\n")); 1771*0Sstevel@tonic-gate return (CFGA_ERROR); 1772*0Sstevel@tonic-gate } 1773*0Sstevel@tonic-gate 1774*0Sstevel@tonic-gate (void) snprintf(ap_log_id, strlen(ap_id) + 1, "%s%i:%s", 1775*0Sstevel@tonic-gate di_driver_name(ap_node), di_instance(ap_node), slot_name); 1776*0Sstevel@tonic-gate 1777*0Sstevel@tonic-gate DBG(1, ("fix_ap_name: %s\n", ap_log_id)); 1778*0Sstevel@tonic-gate 1779*0Sstevel@tonic-gate di_fini(ap_node); 1780*0Sstevel@tonic-gate 1781*0Sstevel@tonic-gate free(buf); 1782*0Sstevel@tonic-gate return (CFGA_OK); 1783*0Sstevel@tonic-gate } 1784*0Sstevel@tonic-gate 1785*0Sstevel@tonic-gate /*ARGSUSED*/ 1786*0Sstevel@tonic-gate cfga_err_t 1787*0Sstevel@tonic-gate cfga_list_ext(const char *ap_id, cfga_list_data_t **cs, 1788*0Sstevel@tonic-gate int *nlist, const char *options, const char *listopts, char **errstring, 1789*0Sstevel@tonic-gate cfga_flags_t flags) 1790*0Sstevel@tonic-gate { 1791*0Sstevel@tonic-gate devctl_hdl_t dcp; 1792*0Sstevel@tonic-gate struct hpc_control_data iocdata; 1793*0Sstevel@tonic-gate devctl_ap_state_t state; 1794*0Sstevel@tonic-gate hpc_board_type_t boardtype; 1795*0Sstevel@tonic-gate hpc_card_info_t cardinfo; 1796*0Sstevel@tonic-gate hpc_slot_info_t slot_info; 1797*0Sstevel@tonic-gate struct searcharg slotname_arg; 1798*0Sstevel@tonic-gate int fd; 1799*0Sstevel@tonic-gate int rv = CFGA_OK; 1800*0Sstevel@tonic-gate 1801*0Sstevel@tonic-gate if ((rv = check_options(options)) != CFGA_OK) { 1802*0Sstevel@tonic-gate return (rv); 1803*0Sstevel@tonic-gate } 1804*0Sstevel@tonic-gate 1805*0Sstevel@tonic-gate if (errstring != NULL) 1806*0Sstevel@tonic-gate *errstring = NULL; 1807*0Sstevel@tonic-gate 1808*0Sstevel@tonic-gate (void) memset(&slot_info, 0, sizeof (hpc_slot_info_t)); 1809*0Sstevel@tonic-gate 1810*0Sstevel@tonic-gate DBG(1, ("cfga_list_ext:(%s)\n", ap_id)); 1811*0Sstevel@tonic-gate 1812*0Sstevel@tonic-gate if (cs == NULL || nlist == NULL) { 1813*0Sstevel@tonic-gate rv = CFGA_ERROR; 1814*0Sstevel@tonic-gate return (rv); 1815*0Sstevel@tonic-gate } 1816*0Sstevel@tonic-gate 1817*0Sstevel@tonic-gate *nlist = 1; 1818*0Sstevel@tonic-gate 1819*0Sstevel@tonic-gate if ((*cs = malloc(sizeof (cfga_list_data_t))) == NULL) { 1820*0Sstevel@tonic-gate cfga_err(errstring, "malloc ", 0); 1821*0Sstevel@tonic-gate DBG(1, ("malloc failed\n")); 1822*0Sstevel@tonic-gate rv = CFGA_ERROR; 1823*0Sstevel@tonic-gate return (rv); 1824*0Sstevel@tonic-gate } 1825*0Sstevel@tonic-gate 1826*0Sstevel@tonic-gate if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) { 1827*0Sstevel@tonic-gate cfga_err(errstring, CMD_GETSTAT, 0); 1828*0Sstevel@tonic-gate DBG(2, ("cfga_list_ext::(devctl_ap_acquire())\n")); 1829*0Sstevel@tonic-gate rv = CFGA_ERROR; 1830*0Sstevel@tonic-gate return (rv); 1831*0Sstevel@tonic-gate } 1832*0Sstevel@tonic-gate 1833*0Sstevel@tonic-gate if (devctl_ap_getstate(dcp, NULL, &state) == -1) { 1834*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, ap_id, 0); 1835*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1836*0Sstevel@tonic-gate DBG(2, ("cfga_list_ext::(devctl_ap_getstate())\n")); 1837*0Sstevel@tonic-gate rv = CFGA_ERROR; 1838*0Sstevel@tonic-gate return (rv); 1839*0Sstevel@tonic-gate } 1840*0Sstevel@tonic-gate 1841*0Sstevel@tonic-gate switch (state.ap_rstate) { 1842*0Sstevel@tonic-gate case AP_RSTATE_EMPTY: 1843*0Sstevel@tonic-gate (*cs)->ap_r_state = CFGA_STAT_EMPTY; 1844*0Sstevel@tonic-gate DBG(2, ("ap_rstate = CFGA_STAT_EMPTY\n")); 1845*0Sstevel@tonic-gate break; 1846*0Sstevel@tonic-gate case AP_RSTATE_DISCONNECTED: 1847*0Sstevel@tonic-gate (*cs)->ap_r_state = CFGA_STAT_DISCONNECTED; 1848*0Sstevel@tonic-gate DBG(2, ("ap_rstate = CFGA_STAT_DISCONNECTED\n")); 1849*0Sstevel@tonic-gate break; 1850*0Sstevel@tonic-gate case AP_RSTATE_CONNECTED: 1851*0Sstevel@tonic-gate (*cs)->ap_r_state = CFGA_STAT_CONNECTED; 1852*0Sstevel@tonic-gate DBG(2, ("ap_rstate = CFGA_STAT_CONNECTED\n")); 1853*0Sstevel@tonic-gate break; 1854*0Sstevel@tonic-gate default: 1855*0Sstevel@tonic-gate cfga_err(errstring, CMD_GETSTAT, ap_id, 0); 1856*0Sstevel@tonic-gate rv = CFGA_ERROR; 1857*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1858*0Sstevel@tonic-gate return (rv); 1859*0Sstevel@tonic-gate } 1860*0Sstevel@tonic-gate 1861*0Sstevel@tonic-gate switch (state.ap_ostate) { 1862*0Sstevel@tonic-gate case AP_OSTATE_CONFIGURED: 1863*0Sstevel@tonic-gate (*cs)->ap_o_state = CFGA_STAT_CONFIGURED; 1864*0Sstevel@tonic-gate DBG(2, ("ap_ostate = CFGA_STAT_CONFIGURED\n")); 1865*0Sstevel@tonic-gate break; 1866*0Sstevel@tonic-gate case AP_OSTATE_UNCONFIGURED: 1867*0Sstevel@tonic-gate (*cs)->ap_o_state = CFGA_STAT_UNCONFIGURED; 1868*0Sstevel@tonic-gate DBG(2, ("ap_ostate = CFGA_STAT_UNCONFIGURED\n")); 1869*0Sstevel@tonic-gate break; 1870*0Sstevel@tonic-gate default: 1871*0Sstevel@tonic-gate cfga_err(errstring, CMD_GETSTAT, ap_id, 0); 1872*0Sstevel@tonic-gate rv = CFGA_ERROR; 1873*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1874*0Sstevel@tonic-gate return (rv); 1875*0Sstevel@tonic-gate } 1876*0Sstevel@tonic-gate 1877*0Sstevel@tonic-gate switch (state.ap_condition) { 1878*0Sstevel@tonic-gate case AP_COND_OK: 1879*0Sstevel@tonic-gate (*cs)->ap_cond = CFGA_COND_OK; 1880*0Sstevel@tonic-gate DBG(2, ("ap_cond = CFGA_COND_OK\n")); 1881*0Sstevel@tonic-gate break; 1882*0Sstevel@tonic-gate case AP_COND_FAILING: 1883*0Sstevel@tonic-gate (*cs)->ap_cond = CFGA_COND_FAILING; 1884*0Sstevel@tonic-gate DBG(2, ("ap_cond = CFGA_COND_FAILING\n")); 1885*0Sstevel@tonic-gate break; 1886*0Sstevel@tonic-gate case AP_COND_FAILED: 1887*0Sstevel@tonic-gate (*cs)->ap_cond = CFGA_COND_FAILED; 1888*0Sstevel@tonic-gate DBG(2, ("ap_cond = CFGA_COND_FAILED\n")); 1889*0Sstevel@tonic-gate break; 1890*0Sstevel@tonic-gate case AP_COND_UNUSABLE: 1891*0Sstevel@tonic-gate (*cs)->ap_cond = CFGA_COND_UNUSABLE; 1892*0Sstevel@tonic-gate DBG(2, ("ap_cond = CFGA_COND_UNUSABLE\n")); 1893*0Sstevel@tonic-gate break; 1894*0Sstevel@tonic-gate case AP_COND_UNKNOWN: 1895*0Sstevel@tonic-gate (*cs)->ap_cond = CFGA_COND_UNKNOWN; 1896*0Sstevel@tonic-gate DBG(2, ("ap_cond = CFGA_COND_UNKNOW\n")); 1897*0Sstevel@tonic-gate break; 1898*0Sstevel@tonic-gate default: 1899*0Sstevel@tonic-gate cfga_err(errstring, CMD_GETSTAT, ap_id, 0); 1900*0Sstevel@tonic-gate rv = CFGA_ERROR; 1901*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1902*0Sstevel@tonic-gate return (rv); 1903*0Sstevel@tonic-gate } 1904*0Sstevel@tonic-gate (*cs)->ap_busy = (int)state.ap_in_transition; 1905*0Sstevel@tonic-gate 1906*0Sstevel@tonic-gate devctl_release((devctl_hdl_t)dcp); 1907*0Sstevel@tonic-gate 1908*0Sstevel@tonic-gate if ((fd = open(ap_id, O_RDWR)) == -1) { 1909*0Sstevel@tonic-gate cfga_err(errstring, ERR_AP_ERR, ap_id, 0); 1910*0Sstevel@tonic-gate (*cs)->ap_status_time = 0; 1911*0Sstevel@tonic-gate boardtype = HPC_BOARD_UNKNOWN; 1912*0Sstevel@tonic-gate cardinfo.base_class = PCI_CLASS_NONE; 1913*0Sstevel@tonic-gate get_logical_name(ap_id, slot_info.pci_slot_name, 0); 1914*0Sstevel@tonic-gate DBG(2, ("open on %s failed\n", ap_id)); 1915*0Sstevel@tonic-gate goto cont; 1916*0Sstevel@tonic-gate } 1917*0Sstevel@tonic-gate DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd)); 1918*0Sstevel@tonic-gate 1919*0Sstevel@tonic-gate (*cs)->ap_status_time = state.ap_last_change; 1920*0Sstevel@tonic-gate 1921*0Sstevel@tonic-gate /* need board type and a way to get to hpc_slot_info */ 1922*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_BOARD_TYPE, 1923*0Sstevel@tonic-gate (void *)&boardtype); 1924*0Sstevel@tonic-gate 1925*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1926*0Sstevel@tonic-gate boardtype = HPC_BOARD_UNKNOWN; 1927*0Sstevel@tonic-gate } 1928*0Sstevel@tonic-gate DBG(1, ("ioctl boardtype\n")); 1929*0Sstevel@tonic-gate 1930*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO, 1931*0Sstevel@tonic-gate (void *)&slot_info); 1932*0Sstevel@tonic-gate 1933*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1934*0Sstevel@tonic-gate get_logical_name(ap_id, slot_info.pci_slot_name, 0); 1935*0Sstevel@tonic-gate DBG(1, ("ioctl failed slotinfo: %s\n", 1936*0Sstevel@tonic-gate slot_info.pci_slot_name)); 1937*0Sstevel@tonic-gate } else { 1938*0Sstevel@tonic-gate 1939*0Sstevel@tonic-gate /* 1940*0Sstevel@tonic-gate * the driver will report back things like hpc0_slot0 1941*0Sstevel@tonic-gate * this needs to be changed to things like pci1:hpc0_slot0 1942*0Sstevel@tonic-gate */ 1943*0Sstevel@tonic-gate rv = fix_ap_name((*cs)->ap_log_id, 1944*0Sstevel@tonic-gate ap_id, slot_info.pci_slot_name, errstring); 1945*0Sstevel@tonic-gate DBG(1, ("ioctl slotinfo: %s\n", (*cs)->ap_log_id)); 1946*0Sstevel@tonic-gate } 1947*0Sstevel@tonic-gate 1948*0Sstevel@tonic-gate build_control_data(&iocdata, HPC_CTRL_GET_CARD_INFO, 1949*0Sstevel@tonic-gate (void *)&cardinfo); 1950*0Sstevel@tonic-gate 1951*0Sstevel@tonic-gate if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) { 1952*0Sstevel@tonic-gate DBG(1, ("ioctl failed\n")); 1953*0Sstevel@tonic-gate cardinfo.base_class = PCI_CLASS_NONE; 1954*0Sstevel@tonic-gate } 1955*0Sstevel@tonic-gate 1956*0Sstevel@tonic-gate DBG(1, ("ioctl cardinfo: %d\n", cardinfo.base_class)); 1957*0Sstevel@tonic-gate DBG(1, ("ioctl subclass: %d\n", cardinfo.sub_class)); 1958*0Sstevel@tonic-gate DBG(1, ("ioctl headertype: %d\n", cardinfo.header_type)); 1959*0Sstevel@tonic-gate 1960*0Sstevel@tonic-gate (void) close(fd); 1961*0Sstevel@tonic-gate 1962*0Sstevel@tonic-gate cont: 1963*0Sstevel@tonic-gate (void) strcpy((*cs)->ap_phys_id, ap_id); /* physical path of AP */ 1964*0Sstevel@tonic-gate if ((*cs)->ap_log_id[0] == '\0') 1965*0Sstevel@tonic-gate (void) strcpy((*cs)->ap_log_id, slot_info.pci_slot_name); 1966*0Sstevel@tonic-gate 1967*0Sstevel@tonic-gate /* slot_names of bus node */ 1968*0Sstevel@tonic-gate if (find_physical_slot_names(ap_id, &slotname_arg) != -1) 1969*0Sstevel@tonic-gate (void) strcpy((*cs)->ap_info, 1970*0Sstevel@tonic-gate slotname_arg.slotnames[slotname_arg.minor]); 1971*0Sstevel@tonic-gate 1972*0Sstevel@tonic-gate (void) memset((*cs)->ap_type, 0, CFGA_TYPE_LEN); 1973*0Sstevel@tonic-gate /* class_code/subclass/boardtype */ 1974*0Sstevel@tonic-gate get_type(boardtype, cardinfo, (*cs)->ap_type); 1975*0Sstevel@tonic-gate 1976*0Sstevel@tonic-gate DBG(1, ("cfga_list_ext return success\n")); 1977*0Sstevel@tonic-gate rv = CFGA_OK; 1978*0Sstevel@tonic-gate 1979*0Sstevel@tonic-gate return (rv); 1980*0Sstevel@tonic-gate } 1981*0Sstevel@tonic-gate 1982*0Sstevel@tonic-gate /* 1983*0Sstevel@tonic-gate * This routine prints a single line of help message 1984*0Sstevel@tonic-gate */ 1985*0Sstevel@tonic-gate static void 1986*0Sstevel@tonic-gate cfga_msg(struct cfga_msg *msgp, const char *str) 1987*0Sstevel@tonic-gate { 1988*0Sstevel@tonic-gate DBG(2, ("<%s>", str)); 1989*0Sstevel@tonic-gate 1990*0Sstevel@tonic-gate if (msgp == NULL || msgp->message_routine == NULL) 1991*0Sstevel@tonic-gate return; 1992*0Sstevel@tonic-gate 1993*0Sstevel@tonic-gate (*msgp->message_routine)(msgp->appdata_ptr, str); 1994*0Sstevel@tonic-gate (*msgp->message_routine)(msgp->appdata_ptr, "\n"); 1995*0Sstevel@tonic-gate } 1996*0Sstevel@tonic-gate 1997*0Sstevel@tonic-gate static cfga_err_t 1998*0Sstevel@tonic-gate check_options(const char *options) 1999*0Sstevel@tonic-gate { 2000*0Sstevel@tonic-gate struct cfga_msg *msgp = NULL; 2001*0Sstevel@tonic-gate 2002*0Sstevel@tonic-gate if (options) { 2003*0Sstevel@tonic-gate cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN])); 2004*0Sstevel@tonic-gate cfga_msg(msgp, options); 2005*0Sstevel@tonic-gate return (CFGA_INVAL); 2006*0Sstevel@tonic-gate } 2007*0Sstevel@tonic-gate return (CFGA_OK); 2008*0Sstevel@tonic-gate } 2009*0Sstevel@tonic-gate 2010*0Sstevel@tonic-gate /*ARGSUSED*/ 2011*0Sstevel@tonic-gate cfga_err_t 2012*0Sstevel@tonic-gate cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags) 2013*0Sstevel@tonic-gate { 2014*0Sstevel@tonic-gate if (options) { 2015*0Sstevel@tonic-gate cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN])); 2016*0Sstevel@tonic-gate cfga_msg(msgp, options); 2017*0Sstevel@tonic-gate } 2018*0Sstevel@tonic-gate DBG(1, ("cfga_help\n")); 2019*0Sstevel@tonic-gate 2020*0Sstevel@tonic-gate cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_HEADER])); 2021*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_CONFIG]); 2022*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_ENABLE_SLOT]); 2023*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_DISABLE_SLOT]); 2024*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_ENABLE_AUTOCONF]); 2025*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_DISABLE_AUTOCONF]); 2026*0Sstevel@tonic-gate cfga_msg(msgp, cfga_strs[HELP_LED_CNTRL]); 2027*0Sstevel@tonic-gate return (CFGA_OK); 2028*0Sstevel@tonic-gate } 2029*0Sstevel@tonic-gate 2030*0Sstevel@tonic-gate /* 2031*0Sstevel@tonic-gate * cfga_err() accepts a variable number of message IDs and constructs 2032*0Sstevel@tonic-gate * a corresponding error string which is returned via the errstring argument. 2033*0Sstevel@tonic-gate * cfga_err() calls gettext() to internationalize proper messages. 2034*0Sstevel@tonic-gate */ 2035*0Sstevel@tonic-gate static void 2036*0Sstevel@tonic-gate cfga_err(char **errstring, ...) 2037*0Sstevel@tonic-gate { 2038*0Sstevel@tonic-gate int a; 2039*0Sstevel@tonic-gate int i; 2040*0Sstevel@tonic-gate int n; 2041*0Sstevel@tonic-gate int len; 2042*0Sstevel@tonic-gate int flen; 2043*0Sstevel@tonic-gate char *p; 2044*0Sstevel@tonic-gate char *q; 2045*0Sstevel@tonic-gate char *s[32]; 2046*0Sstevel@tonic-gate char *failed; 2047*0Sstevel@tonic-gate va_list ap; 2048*0Sstevel@tonic-gate 2049*0Sstevel@tonic-gate /* 2050*0Sstevel@tonic-gate * If errstring is null it means user in not interested in getting 2051*0Sstevel@tonic-gate * error status. So we don't do all the work 2052*0Sstevel@tonic-gate */ 2053*0Sstevel@tonic-gate if (errstring == NULL) { 2054*0Sstevel@tonic-gate return; 2055*0Sstevel@tonic-gate } 2056*0Sstevel@tonic-gate va_start(ap, errstring); 2057*0Sstevel@tonic-gate 2058*0Sstevel@tonic-gate failed = dgettext(TEXT_DOMAIN, cfga_strs[FAILED]); 2059*0Sstevel@tonic-gate flen = strlen(failed); 2060*0Sstevel@tonic-gate 2061*0Sstevel@tonic-gate for (n = len = 0; (a = va_arg(ap, int)) != 0; n++) { 2062*0Sstevel@tonic-gate switch (a) { 2063*0Sstevel@tonic-gate case CMD_GETSTAT: 2064*0Sstevel@tonic-gate case CMD_LIST: 2065*0Sstevel@tonic-gate case CMD_SLOT_CONNECT: 2066*0Sstevel@tonic-gate case CMD_SLOT_DISCONNECT: 2067*0Sstevel@tonic-gate case CMD_SLOT_CONFIGURE: 2068*0Sstevel@tonic-gate case CMD_SLOT_UNCONFIGURE: 2069*0Sstevel@tonic-gate p = cfga_errstrs(a); 2070*0Sstevel@tonic-gate len += (strlen(p) + flen); 2071*0Sstevel@tonic-gate s[n] = p; 2072*0Sstevel@tonic-gate s[++n] = cfga_strs[FAILED]; 2073*0Sstevel@tonic-gate 2074*0Sstevel@tonic-gate DBG(2, ("<%s>", p)); 2075*0Sstevel@tonic-gate DBG(2, (cfga_strs[FAILED])); 2076*0Sstevel@tonic-gate break; 2077*0Sstevel@tonic-gate 2078*0Sstevel@tonic-gate case ERR_CMD_INVAL: 2079*0Sstevel@tonic-gate case ERR_AP_INVAL: 2080*0Sstevel@tonic-gate case ERR_OPT_INVAL: 2081*0Sstevel@tonic-gate case ERR_AP_ERR: 2082*0Sstevel@tonic-gate switch (a) { 2083*0Sstevel@tonic-gate case ERR_CMD_INVAL: 2084*0Sstevel@tonic-gate p = dgettext(TEXT_DOMAIN, 2085*0Sstevel@tonic-gate cfga_errstrs[ERR_CMD_INVAL]); 2086*0Sstevel@tonic-gate break; 2087*0Sstevel@tonic-gate case ERR_AP_INVAL: 2088*0Sstevel@tonic-gate p = dgettext(TEXT_DOMAIN, 2089*0Sstevel@tonic-gate cfga_errstrs[ERR_AP_INVAL]); 2090*0Sstevel@tonic-gate break; 2091*0Sstevel@tonic-gate case ERR_OPT_INVAL: 2092*0Sstevel@tonic-gate p = dgettext(TEXT_DOMAIN, 2093*0Sstevel@tonic-gate cfga_errstrs[ERR_OPT_INVAL]); 2094*0Sstevel@tonic-gate break; 2095*0Sstevel@tonic-gate case ERR_AP_ERR: 2096*0Sstevel@tonic-gate p = dgettext(TEXT_DOMAIN, 2097*0Sstevel@tonic-gate cfga_errstrs[ERR_AP_ERR]); 2098*0Sstevel@tonic-gate break; 2099*0Sstevel@tonic-gate } 2100*0Sstevel@tonic-gate 2101*0Sstevel@tonic-gate if ((q = va_arg(ap, char *)) != NULL) { 2102*0Sstevel@tonic-gate len += (strlen(p) + strlen(q)); 2103*0Sstevel@tonic-gate s[n] = p; 2104*0Sstevel@tonic-gate s[++n] = q; 2105*0Sstevel@tonic-gate DBG(2, ("<%s>", p)); 2106*0Sstevel@tonic-gate DBG(2, ("<%s>", q)); 2107*0Sstevel@tonic-gate break; 2108*0Sstevel@tonic-gate } else { 2109*0Sstevel@tonic-gate len += strlen(p); 2110*0Sstevel@tonic-gate s[n] = p; 2111*0Sstevel@tonic-gate 2112*0Sstevel@tonic-gate } 2113*0Sstevel@tonic-gate DBG(2, ("<%s>", p)); 2114*0Sstevel@tonic-gate break; 2115*0Sstevel@tonic-gate 2116*0Sstevel@tonic-gate default: 2117*0Sstevel@tonic-gate n--; 2118*0Sstevel@tonic-gate break; 2119*0Sstevel@tonic-gate } 2120*0Sstevel@tonic-gate } 2121*0Sstevel@tonic-gate 2122*0Sstevel@tonic-gate DBG(2, ("\n")); 2123*0Sstevel@tonic-gate va_end(ap); 2124*0Sstevel@tonic-gate 2125*0Sstevel@tonic-gate if ((p = calloc(len + 1, 1)) == NULL) 2126*0Sstevel@tonic-gate return; 2127*0Sstevel@tonic-gate 2128*0Sstevel@tonic-gate for (i = 0; i < n; i++) { 2129*0Sstevel@tonic-gate (void) strlcat(p, s[i], len + 1); 2130*0Sstevel@tonic-gate DBG(2, ("i:%d, %s\n", i, s[i])); 2131*0Sstevel@tonic-gate } 2132*0Sstevel@tonic-gate 2133*0Sstevel@tonic-gate *errstring = p; 2134*0Sstevel@tonic-gate #ifdef DEBUG 2135*0Sstevel@tonic-gate printf("%s\n", *errstring); 2136*0Sstevel@tonic-gate free(*errstring); 2137*0Sstevel@tonic-gate #endif 2138*0Sstevel@tonic-gate } 2139*0Sstevel@tonic-gate 2140*0Sstevel@tonic-gate /* 2141*0Sstevel@tonic-gate * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm 2142*0Sstevel@tonic-gate */ 2143