17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 525cf1a30Sjl139090 * Common Development and Distribution License (the "License"). 625cf1a30Sjl139090 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2107d06da5SSurya Prakki 227c478bd9Sstevel@tonic-gate /* 2356f33205SJonathan Adams * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * PIM-DR layer of DR driver. Provides interface between user 297c478bd9Sstevel@tonic-gate * level applications and the PSM-DR layer. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/note.h> 337c478bd9Sstevel@tonic-gate #include <sys/debug.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 367c478bd9Sstevel@tonic-gate #include <sys/cred.h> 377c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 387c478bd9Sstevel@tonic-gate #include <sys/devops.h> 397c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 407c478bd9Sstevel@tonic-gate #include <sys/poll.h> 417c478bd9Sstevel@tonic-gate #include <sys/conf.h> 427c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 437c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 447c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 457c478bd9Sstevel@tonic-gate #include <sys/stat.h> 467c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 477c478bd9Sstevel@tonic-gate #include <sys/processor.h> 487c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 497c478bd9Sstevel@tonic-gate #include <sys/mem_config.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 527c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 557c478bd9Sstevel@tonic-gate #include <sys/promif.h> 567c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <sys/dr.h> 597c478bd9Sstevel@tonic-gate #include <sys/drmach.h> 607c478bd9Sstevel@tonic-gate #include <sys/dr_util.h> 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate extern int nulldev(); 637c478bd9Sstevel@tonic-gate extern int nodev(); 647c478bd9Sstevel@tonic-gate extern struct memlist *phys_install; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #ifdef DEBUG 677c478bd9Sstevel@tonic-gate uint_t dr_debug = 0; /* dr.h for bit values */ 687c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * NOTE: state_str, nt_str and SBD_CMD_STR are only used in a debug 727c478bd9Sstevel@tonic-gate * kernel. They are, however, referenced during both debug and non-debug 737c478bd9Sstevel@tonic-gate * compiles. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate static char *state_str[] = { 777c478bd9Sstevel@tonic-gate "EMPTY", "OCCUPIED", "CONNECTED", "UNCONFIGURED", 787c478bd9Sstevel@tonic-gate "PARTIAL", "CONFIGURED", "RELEASE", "UNREFERENCED", 797c478bd9Sstevel@tonic-gate "FATAL" 807c478bd9Sstevel@tonic-gate }; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define SBD_CMD_STR(c) \ 837c478bd9Sstevel@tonic-gate (((c) == SBD_CMD_ASSIGN) ? "ASSIGN" : \ 847c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_UNASSIGN) ? "UNASSIGN" : \ 857c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_POWERON) ? "POWERON" : \ 867c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_POWEROFF) ? "POWEROFF" : \ 877c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_TEST) ? "TEST" : \ 887c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_CONNECT) ? "CONNECT" : \ 897c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_DISCONNECT) ? "DISCONNECT" : \ 907c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_CONFIGURE) ? "CONFIGURE" : \ 917c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_UNCONFIGURE) ? "UNCONFIGURE" : \ 927c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_GETNCM) ? "GETNCM" : \ 937c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_PASSTHRU) ? "PASSTHRU" : \ 947c478bd9Sstevel@tonic-gate ((c) == SBD_CMD_STATUS) ? "STATUS" : "unknown") 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define DR_GET_BOARD_DEVUNIT(sb, ut, un) (&((sb)->b_dev[NIX(ut)][un])) 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define DR_MAKE_MINOR(i, b) (((i) << 16) | (b)) 997c478bd9Sstevel@tonic-gate #define DR_MINOR2INST(m) (((m) >> 16) & 0xffff) 1007c478bd9Sstevel@tonic-gate #define DR_MINOR2BNUM(m) ((m) & 0xffff) 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* for the DR*INTERNAL_ERROR macros. see sys/dr.h. */ 1037c478bd9Sstevel@tonic-gate static char *dr_ie_fmt = "dr.c %d"; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* struct for drmach device name to sbd_comp_type_t mapping */ 1067c478bd9Sstevel@tonic-gate typedef struct { 1077c478bd9Sstevel@tonic-gate char *s_devtype; 1087c478bd9Sstevel@tonic-gate sbd_comp_type_t s_nodetype; 1097c478bd9Sstevel@tonic-gate } dr_devname_t; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* struct to map starfire device attributes - name:sbd_comp_type_t */ 1127c478bd9Sstevel@tonic-gate static dr_devname_t dr_devattr[] = { 1137c478bd9Sstevel@tonic-gate { DRMACH_DEVTYPE_MEM, SBD_COMP_MEM }, 1147c478bd9Sstevel@tonic-gate { DRMACH_DEVTYPE_CPU, SBD_COMP_CPU }, 1157c478bd9Sstevel@tonic-gate { DRMACH_DEVTYPE_PCI, SBD_COMP_IO }, 11625cf1a30Sjl139090 #if defined(DRMACH_DEVTYPE_SBUS) 1177c478bd9Sstevel@tonic-gate { DRMACH_DEVTYPE_SBUS, SBD_COMP_IO }, 11825cf1a30Sjl139090 #endif 1197c478bd9Sstevel@tonic-gate #if defined(DRMACH_DEVTYPE_WCI) 1207c478bd9Sstevel@tonic-gate { DRMACH_DEVTYPE_WCI, SBD_COMP_IO }, 1217c478bd9Sstevel@tonic-gate #endif 1227c478bd9Sstevel@tonic-gate /* last s_devtype must be NULL, s_nodetype must be SBD_COMP_UNKNOWN */ 1237c478bd9Sstevel@tonic-gate { NULL, SBD_COMP_UNKNOWN } 1247c478bd9Sstevel@tonic-gate }; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Per instance soft-state structure. 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate typedef struct dr_softstate { 1307c478bd9Sstevel@tonic-gate dev_info_t *dip; 1317c478bd9Sstevel@tonic-gate dr_board_t *boards; 1327c478bd9Sstevel@tonic-gate kmutex_t i_lock; 1337c478bd9Sstevel@tonic-gate int dr_initialized; 1347c478bd9Sstevel@tonic-gate } dr_softstate_t; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * dr Global data elements 1387c478bd9Sstevel@tonic-gate */ 1397c478bd9Sstevel@tonic-gate struct dr_global { 1407c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; /* pointer to initialize soft state */ 1417c478bd9Sstevel@tonic-gate kmutex_t lock; 1427c478bd9Sstevel@tonic-gate } dr_g; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate dr_unsafe_devs_t dr_unsafe_devs; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * Table of known passthru commands. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate struct { 1517c478bd9Sstevel@tonic-gate char *pt_name; 1527c478bd9Sstevel@tonic-gate int (*pt_func)(dr_handle_t *); 1537c478bd9Sstevel@tonic-gate } pt_arr[] = { 1547c478bd9Sstevel@tonic-gate "quiesce", dr_pt_test_suspend, 1557c478bd9Sstevel@tonic-gate }; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate int dr_modunload_okay = 0; /* set to non-zero to allow unload */ 1587c478bd9Sstevel@tonic-gate 159*8682d1efSRichard Lowe static int dr_dev_type_to_nt(char *); 160*8682d1efSRichard Lowe 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * State transition table. States valid transitions for "board" state. 1637c478bd9Sstevel@tonic-gate * Recall that non-zero return value terminates operation, however 1647c478bd9Sstevel@tonic-gate * the herrno value is what really indicates an error , if any. 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate static int 1677c478bd9Sstevel@tonic-gate _cmd2index(int c) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * Translate DR CMD to index into dr_state_transition. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate switch (c) { 1737c478bd9Sstevel@tonic-gate case SBD_CMD_CONNECT: return (0); 1747c478bd9Sstevel@tonic-gate case SBD_CMD_DISCONNECT: return (1); 1757c478bd9Sstevel@tonic-gate case SBD_CMD_CONFIGURE: return (2); 1767c478bd9Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: return (3); 1777c478bd9Sstevel@tonic-gate case SBD_CMD_ASSIGN: return (4); 1787c478bd9Sstevel@tonic-gate case SBD_CMD_UNASSIGN: return (5); 1797c478bd9Sstevel@tonic-gate case SBD_CMD_POWERON: return (6); 1807c478bd9Sstevel@tonic-gate case SBD_CMD_POWEROFF: return (7); 1817c478bd9Sstevel@tonic-gate case SBD_CMD_TEST: return (8); 1827c478bd9Sstevel@tonic-gate default: return (-1); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #define CMD2INDEX(c) _cmd2index(c) 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate static struct dr_state_trans { 1897c478bd9Sstevel@tonic-gate int x_cmd; 1907c478bd9Sstevel@tonic-gate struct { 1917c478bd9Sstevel@tonic-gate int x_rv; /* return value of pre_op */ 1927c478bd9Sstevel@tonic-gate int x_err; /* error, if any */ 1937c478bd9Sstevel@tonic-gate } x_op[DR_STATE_MAX]; 1947c478bd9Sstevel@tonic-gate } dr_state_transition[] = { 1957c478bd9Sstevel@tonic-gate { SBD_CMD_CONNECT, 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 1987c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 1997c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2007c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2017c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2027c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2037c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2047c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2057c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate }, 2087c478bd9Sstevel@tonic-gate { SBD_CMD_DISCONNECT, 2097c478bd9Sstevel@tonic-gate { 2107c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2117c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2127c478bd9Sstevel@tonic-gate { 0, 0 }, /* connected */ 2137c478bd9Sstevel@tonic-gate { 0, 0 }, /* unconfigured */ 2147c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2157c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2167c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2177c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2187c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate }, 2217c478bd9Sstevel@tonic-gate { SBD_CMD_CONFIGURE, 2227c478bd9Sstevel@tonic-gate { 2237c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2247c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* occupied */ 2257c478bd9Sstevel@tonic-gate { 0, 0 }, /* connected */ 2267c478bd9Sstevel@tonic-gate { 0, 0 }, /* unconfigured */ 2277c478bd9Sstevel@tonic-gate { 0, 0 }, /* partial */ 2287c478bd9Sstevel@tonic-gate { 0, 0 }, /* configured */ 2297c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2307c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2317c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate }, 2347c478bd9Sstevel@tonic-gate { SBD_CMD_UNCONFIGURE, 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2377c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* occupied */ 2387c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2397c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2407c478bd9Sstevel@tonic-gate { 0, 0 }, /* partial */ 2417c478bd9Sstevel@tonic-gate { 0, 0 }, /* configured */ 2427c478bd9Sstevel@tonic-gate { 0, 0 }, /* release */ 2437c478bd9Sstevel@tonic-gate { 0, 0 }, /* unreferenced */ 2447c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate }, 2477c478bd9Sstevel@tonic-gate { SBD_CMD_ASSIGN, 2487c478bd9Sstevel@tonic-gate { 2497c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 2507c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2517c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2527c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2537c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2547c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2557c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2567c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2577c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate }, 2607c478bd9Sstevel@tonic-gate { SBD_CMD_UNASSIGN, 2617c478bd9Sstevel@tonic-gate { 2627c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 2637c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2647c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2657c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2667c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2677c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2687c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2697c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2707c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate }, 2737c478bd9Sstevel@tonic-gate { SBD_CMD_POWERON, 2747c478bd9Sstevel@tonic-gate { 2757c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 2767c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2777c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2787c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2797c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2807c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2817c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2827c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2837c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate }, 2867c478bd9Sstevel@tonic-gate { SBD_CMD_POWEROFF, 2877c478bd9Sstevel@tonic-gate { 2887c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 2897c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2907c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2917c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2927c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2937c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2947c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2957c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2967c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate }, 2997c478bd9Sstevel@tonic-gate { SBD_CMD_TEST, 3007c478bd9Sstevel@tonic-gate { 3017c478bd9Sstevel@tonic-gate { 0, 0 }, /* empty */ 3027c478bd9Sstevel@tonic-gate { 0, 0 }, /* occupied */ 3037c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 3047c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 3057c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 3067c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 3077c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 3087c478bd9Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 3097c478bd9Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate }, 3127c478bd9Sstevel@tonic-gate }; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate /* 3157c478bd9Sstevel@tonic-gate * Global R/W lock to synchronize access across 3167c478bd9Sstevel@tonic-gate * multiple boards. Users wanting multi-board access 3177c478bd9Sstevel@tonic-gate * must grab WRITE lock, others must grab READ lock. 3187c478bd9Sstevel@tonic-gate */ 3197c478bd9Sstevel@tonic-gate krwlock_t dr_grwlock; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 3227c478bd9Sstevel@tonic-gate * Head of the boardlist used as a reference point for 3237c478bd9Sstevel@tonic-gate * locating board structs. 3247c478bd9Sstevel@tonic-gate * TODO: eliminate dr_boardlist 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate dr_board_t *dr_boardlist; 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate /* 3297c478bd9Sstevel@tonic-gate * DR support functions. 3307c478bd9Sstevel@tonic-gate */ 3317c478bd9Sstevel@tonic-gate static dr_devset_t dr_dev2devset(sbd_comp_id_t *cid); 3327c478bd9Sstevel@tonic-gate static int dr_check_transition(dr_board_t *bp, 3337c478bd9Sstevel@tonic-gate dr_devset_t *devsetp, 3347c478bd9Sstevel@tonic-gate struct dr_state_trans *transp, 3357c478bd9Sstevel@tonic-gate int cmd); 3367c478bd9Sstevel@tonic-gate static int dr_check_unit_attached(dr_common_unit_t *dp); 3377c478bd9Sstevel@tonic-gate static sbd_error_t *dr_init_devlists(dr_board_t *bp); 3387c478bd9Sstevel@tonic-gate static void dr_board_discovery(dr_board_t *bp); 3397c478bd9Sstevel@tonic-gate static int dr_board_init(dr_board_t *bp, dev_info_t *dip, 3407c478bd9Sstevel@tonic-gate int bd); 3417c478bd9Sstevel@tonic-gate static void dr_board_destroy(dr_board_t *bp); 3427c478bd9Sstevel@tonic-gate static void dr_board_transition(dr_board_t *bp, dr_state_t st); 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * DR driver (DDI) entry points. 3467c478bd9Sstevel@tonic-gate */ 3477c478bd9Sstevel@tonic-gate static int dr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, 3487c478bd9Sstevel@tonic-gate void *arg, void **result); 3497c478bd9Sstevel@tonic-gate static int dr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 3507c478bd9Sstevel@tonic-gate static int dr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 3517c478bd9Sstevel@tonic-gate static int dr_probe(dev_info_t *dip); 3527c478bd9Sstevel@tonic-gate static int dr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 3537c478bd9Sstevel@tonic-gate cred_t *cred_p, int *rval_p); 3547c478bd9Sstevel@tonic-gate static int dr_close(dev_t dev, int flag, int otyp, cred_t *cred_p); 3557c478bd9Sstevel@tonic-gate static int dr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p); 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate /* 3587c478bd9Sstevel@tonic-gate * DR command processing operations. 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate static int dr_copyin_iocmd(dr_handle_t *hp); 3627c478bd9Sstevel@tonic-gate static int dr_copyout_iocmd(dr_handle_t *hp); 3637c478bd9Sstevel@tonic-gate static int dr_copyout_errs(dr_handle_t *hp); 3647c478bd9Sstevel@tonic-gate static int dr_pre_op(dr_handle_t *hp); 3657c478bd9Sstevel@tonic-gate static int dr_post_op(dr_handle_t *hp); 3667c478bd9Sstevel@tonic-gate static int dr_exec_op(dr_handle_t *hp); 3677c478bd9Sstevel@tonic-gate static void dr_assign_board(dr_handle_t *hp); 3687c478bd9Sstevel@tonic-gate static void dr_unassign_board(dr_handle_t *hp); 3697c478bd9Sstevel@tonic-gate static void dr_connect(dr_handle_t *hp); 3707c478bd9Sstevel@tonic-gate static int dr_disconnect(dr_handle_t *hp); 3717c478bd9Sstevel@tonic-gate static void dr_dev_configure(dr_handle_t *hp); 3727c478bd9Sstevel@tonic-gate static void dr_dev_release(dr_handle_t *hp); 3737c478bd9Sstevel@tonic-gate static int dr_dev_unconfigure(dr_handle_t *hp); 3747c478bd9Sstevel@tonic-gate static void dr_dev_cancel(dr_handle_t *hp); 3757c478bd9Sstevel@tonic-gate static int dr_dev_status(dr_handle_t *hp); 3767c478bd9Sstevel@tonic-gate static int dr_get_ncm(dr_handle_t *hp); 3777c478bd9Sstevel@tonic-gate static int dr_pt_ioctl(dr_handle_t *hp); 3787c478bd9Sstevel@tonic-gate static void dr_poweron_board(dr_handle_t *hp); 3797c478bd9Sstevel@tonic-gate static void dr_poweroff_board(dr_handle_t *hp); 3807c478bd9Sstevel@tonic-gate static void dr_test_board(dr_handle_t *hp); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate /* 3857c478bd9Sstevel@tonic-gate * Autoconfiguration data structures 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate struct cb_ops dr_cb_ops = { 3897c478bd9Sstevel@tonic-gate dr_open, /* open */ 3907c478bd9Sstevel@tonic-gate dr_close, /* close */ 3917c478bd9Sstevel@tonic-gate nodev, /* strategy */ 3927c478bd9Sstevel@tonic-gate nodev, /* print */ 3937c478bd9Sstevel@tonic-gate nodev, /* dump */ 3947c478bd9Sstevel@tonic-gate nodev, /* read */ 3957c478bd9Sstevel@tonic-gate nodev, /* write */ 3967c478bd9Sstevel@tonic-gate dr_ioctl, /* ioctl */ 3977c478bd9Sstevel@tonic-gate nodev, /* devmap */ 3987c478bd9Sstevel@tonic-gate nodev, /* mmap */ 3997c478bd9Sstevel@tonic-gate nodev, /* segmap */ 4007c478bd9Sstevel@tonic-gate nochpoll, /* chpoll */ 4017c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 4027c478bd9Sstevel@tonic-gate NULL, /* struct streamtab */ 4037c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_MTSAFE, /* compatibility flags */ 4047c478bd9Sstevel@tonic-gate CB_REV, /* Rev */ 4057c478bd9Sstevel@tonic-gate nodev, /* cb_aread */ 4067c478bd9Sstevel@tonic-gate nodev /* cb_awrite */ 4077c478bd9Sstevel@tonic-gate }; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate struct dev_ops dr_dev_ops = { 4107c478bd9Sstevel@tonic-gate DEVO_REV, /* build version */ 4117c478bd9Sstevel@tonic-gate 0, /* dev ref count */ 4127c478bd9Sstevel@tonic-gate dr_getinfo, /* getinfo */ 4137c478bd9Sstevel@tonic-gate nulldev, /* identify */ 4147c478bd9Sstevel@tonic-gate dr_probe, /* probe */ 4157c478bd9Sstevel@tonic-gate dr_attach, /* attach */ 4167c478bd9Sstevel@tonic-gate dr_detach, /* detach */ 4177c478bd9Sstevel@tonic-gate nodev, /* reset */ 4187c478bd9Sstevel@tonic-gate &dr_cb_ops, /* cb_ops */ 4197c478bd9Sstevel@tonic-gate (struct bus_ops *)NULL, /* bus ops */ 42019397407SSherry Moore NULL, /* power */ 42119397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 4227c478bd9Sstevel@tonic-gate }; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 4277c478bd9Sstevel@tonic-gate &mod_driverops, 42819397407SSherry Moore "Dynamic Reconfiguration", 4297c478bd9Sstevel@tonic-gate &dr_dev_ops 4307c478bd9Sstevel@tonic-gate }; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 4337c478bd9Sstevel@tonic-gate MODREV_1, 4347c478bd9Sstevel@tonic-gate (void *)&modldrv, 4357c478bd9Sstevel@tonic-gate NULL 4367c478bd9Sstevel@tonic-gate }; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* 4397c478bd9Sstevel@tonic-gate * Driver entry points. 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate int 4427c478bd9Sstevel@tonic-gate _init(void) 4437c478bd9Sstevel@tonic-gate { 4447c478bd9Sstevel@tonic-gate int err; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * If you need to support multiple nodes (instances), then 4487c478bd9Sstevel@tonic-gate * whatever the maximum number of supported nodes is would 4497c478bd9Sstevel@tonic-gate * need to passed as the third parameter to ddi_soft_state_init(). 4507c478bd9Sstevel@tonic-gate * Alternative would be to dynamically fini and re-init the 4517c478bd9Sstevel@tonic-gate * soft state structure each time a node is attached. 4527c478bd9Sstevel@tonic-gate */ 4537c478bd9Sstevel@tonic-gate err = ddi_soft_state_init((void **)&dr_g.softsp, 4547c478bd9Sstevel@tonic-gate sizeof (dr_softstate_t), 1); 4557c478bd9Sstevel@tonic-gate if (err) 4567c478bd9Sstevel@tonic-gate return (err); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate mutex_init(&dr_g.lock, NULL, MUTEX_DRIVER, NULL); 4597c478bd9Sstevel@tonic-gate rw_init(&dr_grwlock, NULL, RW_DEFAULT, NULL); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate int 4657c478bd9Sstevel@tonic-gate _fini(void) 4667c478bd9Sstevel@tonic-gate { 4677c478bd9Sstevel@tonic-gate int err; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate if ((err = mod_remove(&modlinkage)) != 0) 4707c478bd9Sstevel@tonic-gate return (err); 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate mutex_destroy(&dr_g.lock); 4737c478bd9Sstevel@tonic-gate rw_destroy(&dr_grwlock); 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate ddi_soft_state_fini((void **)&dr_g.softsp); 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate return (0); 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate int 4817c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 4827c478bd9Sstevel@tonic-gate { 4837c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 4877c478bd9Sstevel@tonic-gate static int 4887c478bd9Sstevel@tonic-gate dr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p) 4897c478bd9Sstevel@tonic-gate { 4907c478bd9Sstevel@tonic-gate int instance; 4917c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; 4927c478bd9Sstevel@tonic-gate dr_board_t *bp; 4937c478bd9Sstevel@tonic-gate /* 4947c478bd9Sstevel@tonic-gate * Don't open unless we've attached. 4957c478bd9Sstevel@tonic-gate */ 4967c478bd9Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(*dev)); 4977c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 4987c478bd9Sstevel@tonic-gate if (softsp == NULL) 4997c478bd9Sstevel@tonic-gate return (ENXIO); 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate mutex_enter(&softsp->i_lock); 5027c478bd9Sstevel@tonic-gate if (!softsp->dr_initialized) { 5037c478bd9Sstevel@tonic-gate int bd; 5047c478bd9Sstevel@tonic-gate int rv = 0; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate bp = softsp->boards; 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* initialize each array element */ 5097c478bd9Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++, bp++) { 5107c478bd9Sstevel@tonic-gate rv = dr_board_init(bp, softsp->dip, bd); 5117c478bd9Sstevel@tonic-gate if (rv) 5127c478bd9Sstevel@tonic-gate break; 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate if (rv == 0) { 5167c478bd9Sstevel@tonic-gate softsp->dr_initialized = 1; 5177c478bd9Sstevel@tonic-gate } else { 5187c478bd9Sstevel@tonic-gate /* destroy elements initialized thus far */ 5197c478bd9Sstevel@tonic-gate while (--bp >= softsp->boards) 5207c478bd9Sstevel@tonic-gate dr_board_destroy(bp); 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate /* TODO: should this be another errno val ? */ 5247c478bd9Sstevel@tonic-gate mutex_exit(&softsp->i_lock); 5257c478bd9Sstevel@tonic-gate return (ENXIO); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate mutex_exit(&softsp->i_lock); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate bp = &softsp->boards[DR_MINOR2BNUM(getminor(*dev))]; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate /* 5337c478bd9Sstevel@tonic-gate * prevent opening of a dyn-ap for a board 5347c478bd9Sstevel@tonic-gate * that does not exist 5357c478bd9Sstevel@tonic-gate */ 5367c478bd9Sstevel@tonic-gate if (!bp->b_assigned) { 5377c478bd9Sstevel@tonic-gate if (drmach_board_lookup(bp->b_num, &bp->b_id) != 0) 5387c478bd9Sstevel@tonic-gate return (ENODEV); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate return (0); 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5457c478bd9Sstevel@tonic-gate static int 5467c478bd9Sstevel@tonic-gate dr_close(dev_t dev, int flag, int otyp, cred_t *cred_p) 5477c478bd9Sstevel@tonic-gate { 5487c478bd9Sstevel@tonic-gate return (0); 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate /* 55225cf1a30Sjl139090 * Enable/disable DR features. 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate int dr_enable = 1; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate /*ARGSUSED3*/ 5577c478bd9Sstevel@tonic-gate static int 5587c478bd9Sstevel@tonic-gate dr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 5597c478bd9Sstevel@tonic-gate cred_t *cred_p, int *rval_p) 5607c478bd9Sstevel@tonic-gate { 5617c478bd9Sstevel@tonic-gate int rv = 0; 5627c478bd9Sstevel@tonic-gate int instance; 5637c478bd9Sstevel@tonic-gate int bd; 5647c478bd9Sstevel@tonic-gate dr_handle_t *hp; 5657c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; 5667c478bd9Sstevel@tonic-gate static fn_t f = "dr_ioctl"; 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(dev)); 5717c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 5727c478bd9Sstevel@tonic-gate if (softsp == NULL) { 5737c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "dr%d: module not yet attached", instance); 5747c478bd9Sstevel@tonic-gate return (ENXIO); 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate if (!dr_enable) { 5787c478bd9Sstevel@tonic-gate switch (cmd) { 5797c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 5807c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 5817c478bd9Sstevel@tonic-gate case SBD_CMD_PASSTHRU: 5827c478bd9Sstevel@tonic-gate break; 5837c478bd9Sstevel@tonic-gate default: 5847c478bd9Sstevel@tonic-gate return (ENOTSUP); 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate } 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate bd = DR_MINOR2BNUM(getminor(dev)); 5897c478bd9Sstevel@tonic-gate if (bd >= MAX_BOARDS) 5907c478bd9Sstevel@tonic-gate return (ENXIO); 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate /* get and initialize storage for new handle */ 5937c478bd9Sstevel@tonic-gate hp = GETSTRUCT(dr_handle_t, 1); 5947c478bd9Sstevel@tonic-gate hp->h_bd = &softsp->boards[bd]; 5957c478bd9Sstevel@tonic-gate hp->h_err = NULL; 5967c478bd9Sstevel@tonic-gate hp->h_dev = getminor(dev); 5977c478bd9Sstevel@tonic-gate hp->h_cmd = cmd; 5987c478bd9Sstevel@tonic-gate hp->h_mode = mode; 5997c478bd9Sstevel@tonic-gate hp->h_iap = (sbd_ioctl_arg_t *)arg; 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* copy sbd command into handle */ 6027c478bd9Sstevel@tonic-gate rv = dr_copyin_iocmd(hp); 6037c478bd9Sstevel@tonic-gate if (rv) { 6047c478bd9Sstevel@tonic-gate FREESTRUCT(hp, dr_handle_t, 1); 6057c478bd9Sstevel@tonic-gate return (EINVAL); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate /* translate canonical name to component type */ 6097c478bd9Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_name[0] != '\0') { 6107c478bd9Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_type = 6117c478bd9Sstevel@tonic-gate dr_dev_type_to_nt(hp->h_sbdcmd.cmd_cm.c_id.c_name); 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate PR_ALL("%s: c_name = %s, c_type = %d\n", 6147c478bd9Sstevel@tonic-gate f, 6157c478bd9Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_name, 6167c478bd9Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_type); 6177c478bd9Sstevel@tonic-gate } else { 6187c478bd9Sstevel@tonic-gate /*EMPTY*/ 6197c478bd9Sstevel@tonic-gate PR_ALL("%s: c_name is NULL\n", f); 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate /* determine scope of operation */ 6237c478bd9Sstevel@tonic-gate hp->h_devset = dr_dev2devset(&hp->h_sbdcmd.cmd_cm.c_id); 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate switch (hp->h_cmd) { 6267c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 6277c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 6287c478bd9Sstevel@tonic-gate /* no locks needed for these commands */ 6297c478bd9Sstevel@tonic-gate break; 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate default: 6327c478bd9Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 6337c478bd9Sstevel@tonic-gate mutex_enter(&hp->h_bd->b_lock); 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate /* 6367c478bd9Sstevel@tonic-gate * If we're dealing with memory at all, then we have 6377c478bd9Sstevel@tonic-gate * to keep the "exclusive" global lock held. This is 6387c478bd9Sstevel@tonic-gate * necessary since we will probably need to look at 6397c478bd9Sstevel@tonic-gate * multiple board structs. Otherwise, we only have 6407c478bd9Sstevel@tonic-gate * to deal with the board in question and so can drop 6417c478bd9Sstevel@tonic-gate * the global lock to "shared". 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate rv = DEVSET_IN_SET(hp->h_devset, SBD_COMP_MEM, DEVSET_ANYUNIT); 6447c478bd9Sstevel@tonic-gate if (rv == 0) 6457c478bd9Sstevel@tonic-gate rw_downgrade(&dr_grwlock); 6467c478bd9Sstevel@tonic-gate break; 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate rv = 0; 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate if (rv == 0) 6517c478bd9Sstevel@tonic-gate rv = dr_pre_op(hp); 6527c478bd9Sstevel@tonic-gate if (rv == 0) 6537c478bd9Sstevel@tonic-gate rv = dr_exec_op(hp); 6547c478bd9Sstevel@tonic-gate if (rv == 0) 6557c478bd9Sstevel@tonic-gate rv = dr_post_op(hp); 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate if (rv == -1) 6587c478bd9Sstevel@tonic-gate rv = EIO; 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate if (hp->h_err != NULL) 6617c478bd9Sstevel@tonic-gate if (!(rv = dr_copyout_errs(hp))) 6627c478bd9Sstevel@tonic-gate rv = EIO; 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate /* undo locking, if any, done before dr_pre_op */ 6657c478bd9Sstevel@tonic-gate switch (hp->h_cmd) { 6667c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 6677c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 6687c478bd9Sstevel@tonic-gate break; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate case SBD_CMD_ASSIGN: 6717c478bd9Sstevel@tonic-gate case SBD_CMD_UNASSIGN: 6727c478bd9Sstevel@tonic-gate case SBD_CMD_POWERON: 6737c478bd9Sstevel@tonic-gate case SBD_CMD_POWEROFF: 6747c478bd9Sstevel@tonic-gate case SBD_CMD_CONNECT: 6757c478bd9Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 6767c478bd9Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 6777c478bd9Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 6787c478bd9Sstevel@tonic-gate /* Board changed state. Log a sysevent. */ 6797c478bd9Sstevel@tonic-gate if (rv == 0) 6807c478bd9Sstevel@tonic-gate (void) drmach_log_sysevent(hp->h_bd->b_num, "", 6817c478bd9Sstevel@tonic-gate SE_SLEEP, 1); 6827c478bd9Sstevel@tonic-gate /* Fall through */ 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate default: 6857c478bd9Sstevel@tonic-gate mutex_exit(&hp->h_bd->b_lock); 6867c478bd9Sstevel@tonic-gate rw_exit(&dr_grwlock); 6877c478bd9Sstevel@tonic-gate } 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate if (hp->h_opts.size != 0) 6907c478bd9Sstevel@tonic-gate FREESTRUCT(hp->h_opts.copts, char, hp->h_opts.size); 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate FREESTRUCT(hp, dr_handle_t, 1); 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate return (rv); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6987c478bd9Sstevel@tonic-gate static int 6997c478bd9Sstevel@tonic-gate dr_probe(dev_info_t *dip) 7007c478bd9Sstevel@tonic-gate { 7017c478bd9Sstevel@tonic-gate return (DDI_PROBE_SUCCESS); 7027c478bd9Sstevel@tonic-gate } 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate static int 7057c478bd9Sstevel@tonic-gate dr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 7067c478bd9Sstevel@tonic-gate { 7077c478bd9Sstevel@tonic-gate int rv, rv2; 7087c478bd9Sstevel@tonic-gate int bd; 7097c478bd9Sstevel@tonic-gate int instance; 7107c478bd9Sstevel@tonic-gate sbd_error_t *err; 7117c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate switch (cmd) { 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate case DDI_ATTACH: 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate rv = ddi_soft_state_zalloc(dr_g.softsp, instance); 7227c478bd9Sstevel@tonic-gate if (rv != DDI_SUCCESS) { 7237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "dr%d: failed to alloc soft-state", 7247c478bd9Sstevel@tonic-gate instance); 7257c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate /* initialize softstate structure */ 7297c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 7307c478bd9Sstevel@tonic-gate softsp->dip = dip; 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate mutex_init(&softsp->i_lock, NULL, MUTEX_DRIVER, NULL); 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate /* allocate board array (aka boardlist) */ 7357c478bd9Sstevel@tonic-gate softsp->boards = GETSTRUCT(dr_board_t, MAX_BOARDS); 7367c478bd9Sstevel@tonic-gate 7377c478bd9Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 7387c478bd9Sstevel@tonic-gate dr_boardlist = softsp->boards; 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate /* initialize each array element */ 7417c478bd9Sstevel@tonic-gate rv = DDI_SUCCESS; 7427c478bd9Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++) { 7437c478bd9Sstevel@tonic-gate dr_board_t *bp = &softsp->boards[bd]; 7447c478bd9Sstevel@tonic-gate char *p, *name; 7457c478bd9Sstevel@tonic-gate int l, minor_num; 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate /* 7487c478bd9Sstevel@tonic-gate * initialized board attachment point path 7497c478bd9Sstevel@tonic-gate * (relative to pseudo) in a form immediately 7507c478bd9Sstevel@tonic-gate * reusable as an cfgadm command argument. 7517c478bd9Sstevel@tonic-gate * TODO: clean this up 7527c478bd9Sstevel@tonic-gate */ 7537c478bd9Sstevel@tonic-gate p = bp->b_path; 7547c478bd9Sstevel@tonic-gate l = sizeof (bp->b_path); 7557c478bd9Sstevel@tonic-gate (void) snprintf(p, l, "dr@%d:", instance); 7567c478bd9Sstevel@tonic-gate while (*p != '\0') { 7577c478bd9Sstevel@tonic-gate l--; 7587c478bd9Sstevel@tonic-gate p++; 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate name = p; 7627c478bd9Sstevel@tonic-gate err = drmach_board_name(bd, p, l); 7637c478bd9Sstevel@tonic-gate if (err) { 7647c478bd9Sstevel@tonic-gate sbd_err_clear(&err); 7657c478bd9Sstevel@tonic-gate rv = DDI_FAILURE; 7667c478bd9Sstevel@tonic-gate break; 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate minor_num = DR_MAKE_MINOR(instance, bd); 7707c478bd9Sstevel@tonic-gate rv = ddi_create_minor_node(dip, name, S_IFCHR, 7717c478bd9Sstevel@tonic-gate minor_num, DDI_NT_SBD_ATTACHMENT_POINT, NULL); 7727c478bd9Sstevel@tonic-gate if (rv != DDI_SUCCESS) 7737c478bd9Sstevel@tonic-gate rv = DDI_FAILURE; 7747c478bd9Sstevel@tonic-gate } 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate if (rv == DDI_SUCCESS) { 7777c478bd9Sstevel@tonic-gate /* 7787c478bd9Sstevel@tonic-gate * Announce the node's presence. 7797c478bd9Sstevel@tonic-gate */ 7807c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 7817c478bd9Sstevel@tonic-gate } else { 7827c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * Init registered unsafe devs. 7867c478bd9Sstevel@tonic-gate */ 7877c478bd9Sstevel@tonic-gate dr_unsafe_devs.devnames = NULL; 7887c478bd9Sstevel@tonic-gate rv2 = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 7897c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 7907c478bd9Sstevel@tonic-gate "unsupported-io-drivers", &dr_unsafe_devs.devnames, 7917c478bd9Sstevel@tonic-gate &dr_unsafe_devs.ndevs); 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate if (rv2 != DDI_PROP_SUCCESS) 7947c478bd9Sstevel@tonic-gate dr_unsafe_devs.ndevs = 0; 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate rw_exit(&dr_grwlock); 7977c478bd9Sstevel@tonic-gate return (rv); 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate default: 8007c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8017c478bd9Sstevel@tonic-gate } 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 8047c478bd9Sstevel@tonic-gate } 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate static int 8077c478bd9Sstevel@tonic-gate dr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 8087c478bd9Sstevel@tonic-gate { 8097c478bd9Sstevel@tonic-gate int instance; 8107c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate switch (cmd) { 8137c478bd9Sstevel@tonic-gate case DDI_DETACH: 8147c478bd9Sstevel@tonic-gate if (!dr_modunload_okay) 8157c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 8207c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 8237c478bd9Sstevel@tonic-gate ASSERT(softsp->boards == dr_boardlist); 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate /* remove all minor nodes */ 8267c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate if (softsp->dr_initialized) { 8297c478bd9Sstevel@tonic-gate int bd; 8307c478bd9Sstevel@tonic-gate 8317c478bd9Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++) 8327c478bd9Sstevel@tonic-gate dr_board_destroy(&softsp->boards[bd]); 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate FREESTRUCT(softsp->boards, dr_board_t, MAX_BOARDS); 8367c478bd9Sstevel@tonic-gate mutex_destroy(&softsp->i_lock); 8377c478bd9Sstevel@tonic-gate ddi_soft_state_free(dr_g.softsp, instance); 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate rw_exit(&dr_grwlock); 8407c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate default: 8437c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 8467c478bd9Sstevel@tonic-gate } 8477c478bd9Sstevel@tonic-gate 8487c478bd9Sstevel@tonic-gate static int 8497c478bd9Sstevel@tonic-gate dr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 8507c478bd9Sstevel@tonic-gate { 8517c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(dip)) 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate dev_t dev = (dev_t)arg; 8547c478bd9Sstevel@tonic-gate int instance, error; 8557c478bd9Sstevel@tonic-gate dr_softstate_t *softsp; 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate *result = NULL; 8587c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 8597c478bd9Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(dev)); 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate switch (cmd) { 8627c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 8637c478bd9Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 8647c478bd9Sstevel@tonic-gate if (softsp == NULL) 8657c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8667c478bd9Sstevel@tonic-gate *result = (void *)softsp->dip; 8677c478bd9Sstevel@tonic-gate break; 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 87004580fdfSmathue *result = (void *)(uintptr_t)instance; 8717c478bd9Sstevel@tonic-gate break; 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate default: 8747c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 8757c478bd9Sstevel@tonic-gate break; 8767c478bd9Sstevel@tonic-gate } 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate return (error); 8797c478bd9Sstevel@tonic-gate } 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate /* 8827c478bd9Sstevel@tonic-gate * DR operations. 8837c478bd9Sstevel@tonic-gate */ 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate static int 8867c478bd9Sstevel@tonic-gate dr_copyin_iocmd(dr_handle_t *hp) 8877c478bd9Sstevel@tonic-gate { 8887c478bd9Sstevel@tonic-gate static fn_t f = "dr_copyin_iocmd"; 8897c478bd9Sstevel@tonic-gate sbd_cmd_t *scp = &hp->h_sbdcmd; 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate if (hp->h_iap == NULL) 8927c478bd9Sstevel@tonic-gate return (EINVAL); 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate bzero((caddr_t)scp, sizeof (sbd_cmd_t)); 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 8977c478bd9Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 8987c478bd9Sstevel@tonic-gate sbd_cmd32_t scmd32; 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate bzero((caddr_t)&scmd32, sizeof (sbd_cmd32_t)); 9017c478bd9Sstevel@tonic-gate 9027c478bd9Sstevel@tonic-gate if (ddi_copyin((void *)hp->h_iap, (void *)&scmd32, 9037c478bd9Sstevel@tonic-gate sizeof (sbd_cmd32_t), hp->h_mode)) { 9047c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9057c478bd9Sstevel@tonic-gate "%s: (32bit) failed to copyin " 9067c478bd9Sstevel@tonic-gate "sbdcmd-struct", f); 9077c478bd9Sstevel@tonic-gate return (EFAULT); 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate scp->cmd_cm.c_id.c_type = scmd32.cmd_cm.c_id.c_type; 9107c478bd9Sstevel@tonic-gate scp->cmd_cm.c_id.c_unit = scmd32.cmd_cm.c_id.c_unit; 9117c478bd9Sstevel@tonic-gate bcopy(&scmd32.cmd_cm.c_id.c_name[0], 9127c478bd9Sstevel@tonic-gate &scp->cmd_cm.c_id.c_name[0], OBP_MAXPROPNAME); 9137c478bd9Sstevel@tonic-gate scp->cmd_cm.c_flags = scmd32.cmd_cm.c_flags; 9147c478bd9Sstevel@tonic-gate scp->cmd_cm.c_len = scmd32.cmd_cm.c_len; 91504580fdfSmathue scp->cmd_cm.c_opts = (caddr_t)(uintptr_t)scmd32.cmd_cm.c_opts; 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate switch (hp->h_cmd) { 9187c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 9197c478bd9Sstevel@tonic-gate scp->cmd_stat.s_nbytes = scmd32.cmd_stat.s_nbytes; 9207c478bd9Sstevel@tonic-gate scp->cmd_stat.s_statp = 92104580fdfSmathue (caddr_t)(uintptr_t)scmd32.cmd_stat.s_statp; 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate default: 9247c478bd9Sstevel@tonic-gate break; 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate } 9277c478bd9Sstevel@tonic-gate } else 9287c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 9297c478bd9Sstevel@tonic-gate if (ddi_copyin((void *)hp->h_iap, (void *)scp, 9307c478bd9Sstevel@tonic-gate sizeof (sbd_cmd_t), hp->h_mode) != 0) { 9317c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9327c478bd9Sstevel@tonic-gate "%s: failed to copyin sbdcmd-struct", f); 9337c478bd9Sstevel@tonic-gate return (EFAULT); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate if ((hp->h_opts.size = scp->cmd_cm.c_len) != 0) { 9377c478bd9Sstevel@tonic-gate hp->h_opts.copts = GETSTRUCT(char, scp->cmd_cm.c_len + 1); 9387c478bd9Sstevel@tonic-gate ++hp->h_opts.size; 9397c478bd9Sstevel@tonic-gate if (ddi_copyin((void *)scp->cmd_cm.c_opts, 9407c478bd9Sstevel@tonic-gate (void *)hp->h_opts.copts, 9417c478bd9Sstevel@tonic-gate scp->cmd_cm.c_len, hp->h_mode) != 0) { 9427c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s: failed to copyin options", f); 9437c478bd9Sstevel@tonic-gate return (EFAULT); 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate } 9467c478bd9Sstevel@tonic-gate return (0); 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate 9497c478bd9Sstevel@tonic-gate static int 9507c478bd9Sstevel@tonic-gate dr_copyout_iocmd(dr_handle_t *hp) 9517c478bd9Sstevel@tonic-gate { 9527c478bd9Sstevel@tonic-gate static fn_t f = "dr_copyout_iocmd"; 9537c478bd9Sstevel@tonic-gate sbd_cmd_t *scp = &hp->h_sbdcmd; 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate if (hp->h_iap == NULL) 9567c478bd9Sstevel@tonic-gate return (EINVAL); 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 9597c478bd9Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 9607c478bd9Sstevel@tonic-gate sbd_cmd32_t scmd32; 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate scmd32.cmd_cm.c_id.c_type = scp->cmd_cm.c_id.c_type; 9637c478bd9Sstevel@tonic-gate scmd32.cmd_cm.c_id.c_unit = scp->cmd_cm.c_id.c_unit; 9647c478bd9Sstevel@tonic-gate bcopy(&scp->cmd_cm.c_id.c_name[0], 9657c478bd9Sstevel@tonic-gate &scmd32.cmd_cm.c_id.c_name[0], OBP_MAXPROPNAME); 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate scmd32.cmd_cm.c_flags = scp->cmd_cm.c_flags; 9687c478bd9Sstevel@tonic-gate scmd32.cmd_cm.c_len = scp->cmd_cm.c_len; 96904580fdfSmathue scmd32.cmd_cm.c_opts = (caddr32_t)(uintptr_t)scp->cmd_cm.c_opts; 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate switch (hp->h_cmd) { 9727c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 9737c478bd9Sstevel@tonic-gate scmd32.cmd_getncm.g_ncm = scp->cmd_getncm.g_ncm; 9747c478bd9Sstevel@tonic-gate break; 9757c478bd9Sstevel@tonic-gate default: 9767c478bd9Sstevel@tonic-gate break; 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)&scmd32, (void *)hp->h_iap, 9807c478bd9Sstevel@tonic-gate sizeof (sbd_cmd32_t), hp->h_mode)) { 9817c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9827c478bd9Sstevel@tonic-gate "%s: (32bit) failed to copyout " 9837c478bd9Sstevel@tonic-gate "sbdcmd-struct", f); 9847c478bd9Sstevel@tonic-gate return (EFAULT); 9857c478bd9Sstevel@tonic-gate } 9867c478bd9Sstevel@tonic-gate } else 9877c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 9887c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)scp, (void *)hp->h_iap, 9897c478bd9Sstevel@tonic-gate sizeof (sbd_cmd_t), hp->h_mode) != 0) { 9907c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 9917c478bd9Sstevel@tonic-gate "%s: failed to copyout sbdcmd-struct", f); 9927c478bd9Sstevel@tonic-gate return (EFAULT); 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate return (0); 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate static int 9997c478bd9Sstevel@tonic-gate dr_copyout_errs(dr_handle_t *hp) 10007c478bd9Sstevel@tonic-gate { 10017c478bd9Sstevel@tonic-gate static fn_t f = "dr_copyout_errs"; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) 10047c478bd9Sstevel@tonic-gate return (0); 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate if (hp->h_err->e_code) { 10077c478bd9Sstevel@tonic-gate PR_ALL("%s: error %d %s", 10087c478bd9Sstevel@tonic-gate f, hp->h_err->e_code, hp->h_err->e_rsc); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 10127c478bd9Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 10137c478bd9Sstevel@tonic-gate sbd_error32_t *serr32p; 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate serr32p = GETSTRUCT(sbd_error32_t, 1); 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate serr32p->e_code = hp->h_err->e_code; 10187c478bd9Sstevel@tonic-gate bcopy(&hp->h_err->e_rsc[0], &serr32p->e_rsc[0], 10197c478bd9Sstevel@tonic-gate MAXPATHLEN); 10207c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)serr32p, 10217c478bd9Sstevel@tonic-gate (void *)&((sbd_ioctl_arg32_t *)hp->h_iap)->i_err, 10227c478bd9Sstevel@tonic-gate sizeof (sbd_error32_t), hp->h_mode)) { 10237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 10247c478bd9Sstevel@tonic-gate "%s: (32bit) failed to copyout", f); 10257c478bd9Sstevel@tonic-gate return (EFAULT); 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate FREESTRUCT(serr32p, sbd_error32_t, 1); 10287c478bd9Sstevel@tonic-gate } else 10297c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 10307c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)hp->h_err, 10317c478bd9Sstevel@tonic-gate (void *)&hp->h_iap->i_err, 10327c478bd9Sstevel@tonic-gate sizeof (sbd_error_t), hp->h_mode)) { 10337c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 10347c478bd9Sstevel@tonic-gate "%s: failed to copyout", f); 10357c478bd9Sstevel@tonic-gate return (EFAULT); 10367c478bd9Sstevel@tonic-gate } 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate sbd_err_clear(&hp->h_err); 10397c478bd9Sstevel@tonic-gate 10407c478bd9Sstevel@tonic-gate return (0); 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate } 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate /* 10457c478bd9Sstevel@tonic-gate * pre-op entry point must sbd_err_set_c(), if needed. 10467c478bd9Sstevel@tonic-gate * Return value of non-zero indicates failure. 10477c478bd9Sstevel@tonic-gate */ 10487c478bd9Sstevel@tonic-gate static int 10497c478bd9Sstevel@tonic-gate dr_pre_op(dr_handle_t *hp) 10507c478bd9Sstevel@tonic-gate { 10517c478bd9Sstevel@tonic-gate int rv = 0, t; 10527c478bd9Sstevel@tonic-gate int cmd, serr = 0; 10537c478bd9Sstevel@tonic-gate dr_devset_t devset; 10547c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 10557c478bd9Sstevel@tonic-gate dr_handle_t *shp = hp; 10567c478bd9Sstevel@tonic-gate static fn_t f = "dr_pre_op"; 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate cmd = hp->h_cmd; 10597c478bd9Sstevel@tonic-gate devset = shp->h_devset; 10607c478bd9Sstevel@tonic-gate 106104580fdfSmathue PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd)); 10627c478bd9Sstevel@tonic-gate 10637c478bd9Sstevel@tonic-gate hp->h_err = drmach_pre_op(cmd, bp->b_id, &hp->h_opts); 10647c478bd9Sstevel@tonic-gate if (hp->h_err != NULL) { 10657c478bd9Sstevel@tonic-gate PR_ALL("drmach_pre_op failed for cmd %s(%d)\n", 10667c478bd9Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 10677c478bd9Sstevel@tonic-gate return (-1); 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate /* 10717c478bd9Sstevel@tonic-gate * Check for valid state transitions. 10727c478bd9Sstevel@tonic-gate */ 10737c478bd9Sstevel@tonic-gate if ((t = CMD2INDEX(cmd)) != -1) { 10747c478bd9Sstevel@tonic-gate struct dr_state_trans *transp; 10757c478bd9Sstevel@tonic-gate int state_err; 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate transp = &dr_state_transition[t]; 10787c478bd9Sstevel@tonic-gate ASSERT(transp->x_cmd == cmd); 10797c478bd9Sstevel@tonic-gate 10807c478bd9Sstevel@tonic-gate state_err = dr_check_transition(bp, &devset, transp, cmd); 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate if (state_err < 0) { 10837c478bd9Sstevel@tonic-gate /* 10847c478bd9Sstevel@tonic-gate * Invalidate device. 10857c478bd9Sstevel@tonic-gate */ 10867c478bd9Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_INVAL, NULL); 10877c478bd9Sstevel@tonic-gate serr = -1; 10887c478bd9Sstevel@tonic-gate PR_ALL("%s: invalid devset (0x%x)\n", 10897c478bd9Sstevel@tonic-gate f, (uint_t)devset); 10907c478bd9Sstevel@tonic-gate } else if (state_err != 0) { 10917c478bd9Sstevel@tonic-gate /* 10927c478bd9Sstevel@tonic-gate * State transition is not a valid one. 10937c478bd9Sstevel@tonic-gate */ 10947c478bd9Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, 10957c478bd9Sstevel@tonic-gate transp->x_op[state_err].x_err, NULL); 10967c478bd9Sstevel@tonic-gate 10977c478bd9Sstevel@tonic-gate serr = transp->x_op[state_err].x_rv; 10987c478bd9Sstevel@tonic-gate 10997c478bd9Sstevel@tonic-gate PR_ALL("%s: invalid state %s(%d) for cmd %s(%d)\n", 11007c478bd9Sstevel@tonic-gate f, state_str[state_err], state_err, 11017c478bd9Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 11027c478bd9Sstevel@tonic-gate } else { 11037c478bd9Sstevel@tonic-gate shp->h_devset = devset; 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate } 11067c478bd9Sstevel@tonic-gate 11077c478bd9Sstevel@tonic-gate if (serr) { 11087c478bd9Sstevel@tonic-gate rv = -1; 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate return (rv); 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate static int 11157c478bd9Sstevel@tonic-gate dr_post_op(dr_handle_t *hp) 11167c478bd9Sstevel@tonic-gate { 11177c478bd9Sstevel@tonic-gate int rv = 0; 11187c478bd9Sstevel@tonic-gate int cmd; 11197c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 11207c478bd9Sstevel@tonic-gate static fn_t f = "dr_post_op"; 11217c478bd9Sstevel@tonic-gate 11227c478bd9Sstevel@tonic-gate cmd = hp->h_cmd; 11237c478bd9Sstevel@tonic-gate 112404580fdfSmathue PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd)); 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate /* errors should have been caught by now */ 11277c478bd9Sstevel@tonic-gate ASSERT(hp->h_err == NULL); 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate hp->h_err = drmach_post_op(cmd, bp->b_id, &hp->h_opts); 11307c478bd9Sstevel@tonic-gate if (hp->h_err != NULL) { 11317c478bd9Sstevel@tonic-gate PR_ALL("drmach_post_op failed for cmd %s(%d)\n", 11327c478bd9Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 11337c478bd9Sstevel@tonic-gate return (-1); 11347c478bd9Sstevel@tonic-gate } 11357c478bd9Sstevel@tonic-gate 11367c478bd9Sstevel@tonic-gate switch (cmd) { 11377c478bd9Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 11387c478bd9Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 11397c478bd9Sstevel@tonic-gate case SBD_CMD_CONNECT: 11407c478bd9Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 11417c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 11427c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 11437c478bd9Sstevel@tonic-gate break; 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate default: 11467c478bd9Sstevel@tonic-gate break; 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate return (rv); 11507c478bd9Sstevel@tonic-gate } 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate static int 11537c478bd9Sstevel@tonic-gate dr_exec_op(dr_handle_t *hp) 11547c478bd9Sstevel@tonic-gate { 11557c478bd9Sstevel@tonic-gate int rv = 0; 11567c478bd9Sstevel@tonic-gate static fn_t f = "dr_exec_op"; 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate /* errors should have been caught by now */ 11597c478bd9Sstevel@tonic-gate ASSERT(hp->h_err == NULL); 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate switch (hp->h_cmd) { 11627c478bd9Sstevel@tonic-gate case SBD_CMD_ASSIGN: 11637c478bd9Sstevel@tonic-gate dr_assign_board(hp); 11647c478bd9Sstevel@tonic-gate break; 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate case SBD_CMD_UNASSIGN: 11677c478bd9Sstevel@tonic-gate dr_unassign_board(hp); 11687c478bd9Sstevel@tonic-gate break; 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate case SBD_CMD_POWEROFF: 11717c478bd9Sstevel@tonic-gate dr_poweroff_board(hp); 11727c478bd9Sstevel@tonic-gate break; 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate case SBD_CMD_POWERON: 11757c478bd9Sstevel@tonic-gate dr_poweron_board(hp); 11767c478bd9Sstevel@tonic-gate break; 11777c478bd9Sstevel@tonic-gate 11787c478bd9Sstevel@tonic-gate case SBD_CMD_TEST: 11797c478bd9Sstevel@tonic-gate dr_test_board(hp); 11807c478bd9Sstevel@tonic-gate break; 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate case SBD_CMD_CONNECT: 11837c478bd9Sstevel@tonic-gate dr_connect(hp); 11847c478bd9Sstevel@tonic-gate break; 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 11877c478bd9Sstevel@tonic-gate dr_dev_configure(hp); 11887c478bd9Sstevel@tonic-gate break; 11897c478bd9Sstevel@tonic-gate 11907c478bd9Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 11917c478bd9Sstevel@tonic-gate dr_dev_release(hp); 11927c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) 11937c478bd9Sstevel@tonic-gate rv = dr_dev_unconfigure(hp); 11947c478bd9Sstevel@tonic-gate else 11957c478bd9Sstevel@tonic-gate dr_dev_cancel(hp); 11967c478bd9Sstevel@tonic-gate break; 11977c478bd9Sstevel@tonic-gate 11987c478bd9Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 11997c478bd9Sstevel@tonic-gate rv = dr_disconnect(hp); 12007c478bd9Sstevel@tonic-gate break; 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate case SBD_CMD_STATUS: 12037c478bd9Sstevel@tonic-gate rv = dr_dev_status(hp); 12047c478bd9Sstevel@tonic-gate break; 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate case SBD_CMD_GETNCM: 12077c478bd9Sstevel@tonic-gate hp->h_sbdcmd.cmd_getncm.g_ncm = dr_get_ncm(hp); 12087c478bd9Sstevel@tonic-gate rv = dr_copyout_iocmd(hp); 12097c478bd9Sstevel@tonic-gate break; 12107c478bd9Sstevel@tonic-gate 12117c478bd9Sstevel@tonic-gate case SBD_CMD_PASSTHRU: 12127c478bd9Sstevel@tonic-gate rv = dr_pt_ioctl(hp); 12137c478bd9Sstevel@tonic-gate break; 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate default: 12167c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 12177c478bd9Sstevel@tonic-gate "%s: unknown command (%d)", 12187c478bd9Sstevel@tonic-gate f, hp->h_cmd); 12197c478bd9Sstevel@tonic-gate break; 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate if (hp->h_err != NULL) { 12237c478bd9Sstevel@tonic-gate rv = -1; 12247c478bd9Sstevel@tonic-gate } 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate return (rv); 12277c478bd9Sstevel@tonic-gate } 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate static void 12307c478bd9Sstevel@tonic-gate dr_assign_board(dr_handle_t *hp) 12317c478bd9Sstevel@tonic-gate { 12327c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_assign(bp->b_num, &bp->b_id); 12357c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) { 12367c478bd9Sstevel@tonic-gate bp->b_assigned = 1; 12377c478bd9Sstevel@tonic-gate } 12387c478bd9Sstevel@tonic-gate } 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate static void 12417c478bd9Sstevel@tonic-gate dr_unassign_board(dr_handle_t *hp) 12427c478bd9Sstevel@tonic-gate { 12437c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12447c478bd9Sstevel@tonic-gate 12457c478bd9Sstevel@tonic-gate /* 12467c478bd9Sstevel@tonic-gate * Block out status during unassign. 12477c478bd9Sstevel@tonic-gate * Not doing cv_wait_sig here as starfire SSP software 12487c478bd9Sstevel@tonic-gate * ignores unassign failure and removes board from 12497c478bd9Sstevel@tonic-gate * domain mask causing system panic. 12507c478bd9Sstevel@tonic-gate * TODO: Change cv_wait to cv_wait_sig when SSP software 12517c478bd9Sstevel@tonic-gate * handles unassign failure. 12527c478bd9Sstevel@tonic-gate */ 12537c478bd9Sstevel@tonic-gate dr_lock_status(bp); 12547c478bd9Sstevel@tonic-gate 12557c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_unassign(bp->b_id); 12567c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) { 12577c478bd9Sstevel@tonic-gate /* 12587c478bd9Sstevel@tonic-gate * clear drmachid_t handle; not valid after board unassign 12597c478bd9Sstevel@tonic-gate */ 12607c478bd9Sstevel@tonic-gate bp->b_id = 0; 12617c478bd9Sstevel@tonic-gate bp->b_assigned = 0; 12627c478bd9Sstevel@tonic-gate } 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate dr_unlock_status(bp); 12657c478bd9Sstevel@tonic-gate } 12667c478bd9Sstevel@tonic-gate 12677c478bd9Sstevel@tonic-gate static void 12687c478bd9Sstevel@tonic-gate dr_poweron_board(dr_handle_t *hp) 12697c478bd9Sstevel@tonic-gate { 12707c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_poweron(bp->b_id); 12737c478bd9Sstevel@tonic-gate } 12747c478bd9Sstevel@tonic-gate 12757c478bd9Sstevel@tonic-gate static void 12767c478bd9Sstevel@tonic-gate dr_poweroff_board(dr_handle_t *hp) 12777c478bd9Sstevel@tonic-gate { 12787c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_poweroff(bp->b_id); 12817c478bd9Sstevel@tonic-gate } 12827c478bd9Sstevel@tonic-gate 12837c478bd9Sstevel@tonic-gate static void 12847c478bd9Sstevel@tonic-gate dr_test_board(dr_handle_t *hp) 12857c478bd9Sstevel@tonic-gate { 12867c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12877c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_test(bp->b_id, &hp->h_opts, 12887c478bd9Sstevel@tonic-gate dr_cmd_flags(hp) & SBD_FLAG_FORCE); 12897c478bd9Sstevel@tonic-gate } 12907c478bd9Sstevel@tonic-gate 12917c478bd9Sstevel@tonic-gate /* 12927c478bd9Sstevel@tonic-gate * Create and populate the component nodes for a board. Assumes that the 12937c478bd9Sstevel@tonic-gate * devlists for the board have been initialized. 12947c478bd9Sstevel@tonic-gate */ 12957c478bd9Sstevel@tonic-gate static void 12967c478bd9Sstevel@tonic-gate dr_make_comp_nodes(dr_board_t *bp) { 12977c478bd9Sstevel@tonic-gate 12987c478bd9Sstevel@tonic-gate int i; 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate /* 13017c478bd9Sstevel@tonic-gate * Make nodes for the individual components on the board. 13027c478bd9Sstevel@tonic-gate * First we need to initialize memory unit data structures of board 13037c478bd9Sstevel@tonic-gate * structure. 13047c478bd9Sstevel@tonic-gate */ 13057c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 13067c478bd9Sstevel@tonic-gate dr_mem_unit_t *mp; 13077c478bd9Sstevel@tonic-gate 13087c478bd9Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 13097c478bd9Sstevel@tonic-gate dr_init_mem_unit(mp); 13107c478bd9Sstevel@tonic-gate } 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate /* 13137c478bd9Sstevel@tonic-gate * Initialize cpu unit data structures. 13147c478bd9Sstevel@tonic-gate */ 13157c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 13167c478bd9Sstevel@tonic-gate dr_cpu_unit_t *cp; 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 13197c478bd9Sstevel@tonic-gate dr_init_cpu_unit(cp); 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate /* 13237c478bd9Sstevel@tonic-gate * Initialize io unit data structures. 13247c478bd9Sstevel@tonic-gate */ 13257c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 13267c478bd9Sstevel@tonic-gate dr_io_unit_t *ip; 13277c478bd9Sstevel@tonic-gate 13287c478bd9Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 13297c478bd9Sstevel@tonic-gate dr_init_io_unit(ip); 13307c478bd9Sstevel@tonic-gate } 13317c478bd9Sstevel@tonic-gate 13327c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONNECTED); 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 13357c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 13367c478bd9Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 13377c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate } 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate /* 13427c478bd9Sstevel@tonic-gate * Only do work if called to operate on an entire board 13437c478bd9Sstevel@tonic-gate * which doesn't already have components present. 13447c478bd9Sstevel@tonic-gate */ 13457c478bd9Sstevel@tonic-gate static void 13467c478bd9Sstevel@tonic-gate dr_connect(dr_handle_t *hp) 13477c478bd9Sstevel@tonic-gate { 13487c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 13497c478bd9Sstevel@tonic-gate static fn_t f = "dr_connect"; 13507c478bd9Sstevel@tonic-gate 13517c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp)) { 13547c478bd9Sstevel@tonic-gate /* 13557c478bd9Sstevel@tonic-gate * Board already has devices present. 13567c478bd9Sstevel@tonic-gate */ 135725cf1a30Sjl139090 PR_ALL("%s: devices already present (0x%lx)\n", 13587c478bd9Sstevel@tonic-gate f, DR_DEVS_PRESENT(bp)); 13597c478bd9Sstevel@tonic-gate return; 13607c478bd9Sstevel@tonic-gate } 13617c478bd9Sstevel@tonic-gate 13627c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_connect(bp->b_id, &hp->h_opts); 13637c478bd9Sstevel@tonic-gate if (hp->h_err) 13647c478bd9Sstevel@tonic-gate return; 13657c478bd9Sstevel@tonic-gate 13667c478bd9Sstevel@tonic-gate hp->h_err = dr_init_devlists(bp); 13677c478bd9Sstevel@tonic-gate if (hp->h_err) 13687c478bd9Sstevel@tonic-gate return; 13697c478bd9Sstevel@tonic-gate else if (bp->b_ndev == 0) { 13707c478bd9Sstevel@tonic-gate dr_op_err(CE_WARN, hp, ESBD_EMPTY_BD, bp->b_path); 13717c478bd9Sstevel@tonic-gate return; 13727c478bd9Sstevel@tonic-gate } else { 13737c478bd9Sstevel@tonic-gate dr_make_comp_nodes(bp); 13747c478bd9Sstevel@tonic-gate return; 13757c478bd9Sstevel@tonic-gate } 13767c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 13777c478bd9Sstevel@tonic-gate } 13787c478bd9Sstevel@tonic-gate 13797c478bd9Sstevel@tonic-gate static int 13807c478bd9Sstevel@tonic-gate dr_disconnect(dr_handle_t *hp) 13817c478bd9Sstevel@tonic-gate { 13827c478bd9Sstevel@tonic-gate int i; 13837c478bd9Sstevel@tonic-gate dr_devset_t devset; 13847c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 13857c478bd9Sstevel@tonic-gate static fn_t f = "dr_disconnect"; 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate /* 13907c478bd9Sstevel@tonic-gate * Only devices which are present, but 13917c478bd9Sstevel@tonic-gate * unattached can be disconnected. 13927c478bd9Sstevel@tonic-gate */ 13937c478bd9Sstevel@tonic-gate devset = hp->h_devset & DR_DEVS_PRESENT(bp) & 13947c478bd9Sstevel@tonic-gate DR_DEVS_UNATTACHED(bp); 13957c478bd9Sstevel@tonic-gate 13967c478bd9Sstevel@tonic-gate if ((devset == 0) && DR_DEVS_PRESENT(bp)) { 13977c478bd9Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_EMPTY_BD, bp->b_path); 13987c478bd9Sstevel@tonic-gate return (0); 13997c478bd9Sstevel@tonic-gate } 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate /* 14027c478bd9Sstevel@tonic-gate * Block out status during disconnect. 14037c478bd9Sstevel@tonic-gate */ 14047c478bd9Sstevel@tonic-gate mutex_enter(&bp->b_slock); 14057c478bd9Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 14067c478bd9Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 14077c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 14087c478bd9Sstevel@tonic-gate return (EINTR); 14097c478bd9Sstevel@tonic-gate } 14107c478bd9Sstevel@tonic-gate } 14117c478bd9Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 14127c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_disconnect(bp->b_id, &hp->h_opts); 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, devset); 14177c478bd9Sstevel@tonic-gate 14187c478bd9Sstevel@tonic-gate ASSERT((DR_DEVS_ATTACHED(bp) & devset) == 0); 14197c478bd9Sstevel@tonic-gate 14207c478bd9Sstevel@tonic-gate /* 14217c478bd9Sstevel@tonic-gate * Update per-device state transitions. 14227c478bd9Sstevel@tonic-gate */ 14237c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 14247c478bd9Sstevel@tonic-gate dr_cpu_unit_t *cp; 14257c478bd9Sstevel@tonic-gate 14267c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_CPU, i)) 14277c478bd9Sstevel@tonic-gate continue; 14287c478bd9Sstevel@tonic-gate 14297c478bd9Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 14307c478bd9Sstevel@tonic-gate if (dr_disconnect_cpu(cp) == 0) 14317c478bd9Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY); 14327c478bd9Sstevel@tonic-gate else if (cp->sbc_cm.sbdev_error != NULL) 14337c478bd9Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &cp->sbc_cm.sbdev_error); 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate ASSERT(cp->sbc_cm.sbdev_error == NULL); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 14397c478bd9Sstevel@tonic-gate dr_mem_unit_t *mp; 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_MEM, i)) 14427c478bd9Sstevel@tonic-gate continue; 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 14457c478bd9Sstevel@tonic-gate if (dr_disconnect_mem(mp) == 0) 14467c478bd9Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY); 14477c478bd9Sstevel@tonic-gate else if (mp->sbm_cm.sbdev_error != NULL) 14487c478bd9Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &mp->sbm_cm.sbdev_error); 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate ASSERT(mp->sbm_cm.sbdev_error == NULL); 14517c478bd9Sstevel@tonic-gate } 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 14547c478bd9Sstevel@tonic-gate dr_io_unit_t *ip; 14557c478bd9Sstevel@tonic-gate 14567c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_IO, i)) 14577c478bd9Sstevel@tonic-gate continue; 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 14607c478bd9Sstevel@tonic-gate if (dr_disconnect_io(ip) == 0) 14617c478bd9Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY); 14627c478bd9Sstevel@tonic-gate else if (ip->sbi_cm.sbdev_error != NULL) 14637c478bd9Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &ip->sbi_cm.sbdev_error); 14647c478bd9Sstevel@tonic-gate 14657c478bd9Sstevel@tonic-gate ASSERT(ip->sbi_cm.sbdev_error == NULL); 14667c478bd9Sstevel@tonic-gate } 14677c478bd9Sstevel@tonic-gate if (hp->h_err) { 14687c478bd9Sstevel@tonic-gate /* 14697c478bd9Sstevel@tonic-gate * For certain errors, drmach_board_disconnect will mark 14707c478bd9Sstevel@tonic-gate * the board as unusable; in these cases the devtree must 14717c478bd9Sstevel@tonic-gate * be purged so that status calls will succeed. 14727c478bd9Sstevel@tonic-gate * XXX 14737c478bd9Sstevel@tonic-gate * This implementation checks for discrete error codes - 14747c478bd9Sstevel@tonic-gate * someday, the i/f to drmach_board_disconnect should be 14757c478bd9Sstevel@tonic-gate * changed to avoid the e_code testing. 14767c478bd9Sstevel@tonic-gate */ 14777c478bd9Sstevel@tonic-gate if ((hp->h_err->e_code == ESTC_MBXRPLY) || 14787c478bd9Sstevel@tonic-gate (hp->h_err->e_code == ESTC_MBXRQST) || 14797c478bd9Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_UNRECOVERABLE) || 14807c478bd9Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_RECOVERABLE) || 148168ac2337Sjl139090 (hp->h_err->e_code == ESTC_DEPROBE) || 148268ac2337Sjl139090 (hp->h_err->e_code == EOPL_DEPROBE)) { 14837c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 14847c478bd9Sstevel@tonic-gate bp->b_busy = 0; 14857c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate if (drmach_board_deprobe(bp->b_id)) 14887c478bd9Sstevel@tonic-gate goto disconnect_done; 14897c478bd9Sstevel@tonic-gate else 14907c478bd9Sstevel@tonic-gate bp->b_ndev = 0; 14917c478bd9Sstevel@tonic-gate } 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate /* 14947c478bd9Sstevel@tonic-gate * If the disconnect failed in a recoverable way, 14957c478bd9Sstevel@tonic-gate * more work is required. 14967c478bd9Sstevel@tonic-gate * XXX 14977c478bd9Sstevel@tonic-gate * This implementation checks for discrete error codes - 14987c478bd9Sstevel@tonic-gate * someday, the i/f to drmach_board_disconnect should be 14997c478bd9Sstevel@tonic-gate * changed to avoid the e_code testing. 15007c478bd9Sstevel@tonic-gate */ 15017c478bd9Sstevel@tonic-gate if ((hp->h_err->e_code == ESTC_MBXRQST) || 15027c478bd9Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_RECOVERABLE) || 150368ac2337Sjl139090 (hp->h_err->e_code == ESTC_DEPROBE) || 150468ac2337Sjl139090 (hp->h_err->e_code == EOPL_DEPROBE)) { 15057c478bd9Sstevel@tonic-gate /* 15067c478bd9Sstevel@tonic-gate * With this failure, the board has been deprobed 15077c478bd9Sstevel@tonic-gate * by IKP, and reprobed. We've already gotten rid 15087c478bd9Sstevel@tonic-gate * of the old devtree, now we need to reconstruct it 15097c478bd9Sstevel@tonic-gate * based on the new IKP probe 15107c478bd9Sstevel@tonic-gate */ 15117c478bd9Sstevel@tonic-gate if (dr_init_devlists(bp) || (bp->b_ndev == 0)) 15127c478bd9Sstevel@tonic-gate goto disconnect_done; 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate dr_make_comp_nodes(bp); 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate /* 15187c478bd9Sstevel@tonic-gate * Once all the components on a board have been disconnect 15197c478bd9Sstevel@tonic-gate * the board's state can transition to disconnected and 15207c478bd9Sstevel@tonic-gate * we can allow the deprobe to take place. 15217c478bd9Sstevel@tonic-gate */ 15227c478bd9Sstevel@tonic-gate if (hp->h_err == NULL && DR_DEVS_PRESENT(bp) == 0) { 15237c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_OCCUPIED); 15247c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_DISCONNECTED; 15257c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 15267c478bd9Sstevel@tonic-gate bp->b_busy = 0; 15277c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 15287c478bd9Sstevel@tonic-gate 15297c478bd9Sstevel@tonic-gate hp->h_err = drmach_board_deprobe(bp->b_id); 15307c478bd9Sstevel@tonic-gate 15317c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) { 15327c478bd9Sstevel@tonic-gate bp->b_ndev = 0; 15337c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 15347c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 15357c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 15367c478bd9Sstevel@tonic-gate } 15377c478bd9Sstevel@tonic-gate } 15387c478bd9Sstevel@tonic-gate 15397c478bd9Sstevel@tonic-gate disconnect_done: 15407c478bd9Sstevel@tonic-gate dr_unlock_status(bp); 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate return (0); 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate /* 15467c478bd9Sstevel@tonic-gate * Check if a particular device is a valid target of the current 15477c478bd9Sstevel@tonic-gate * operation. Return 1 if it is a valid target, and 0 otherwise. 15487c478bd9Sstevel@tonic-gate */ 15497c478bd9Sstevel@tonic-gate static int 15507c478bd9Sstevel@tonic-gate dr_dev_is_target(dr_dev_unit_t *dp, int present_only, uint_t uset) 15517c478bd9Sstevel@tonic-gate { 15527c478bd9Sstevel@tonic-gate dr_common_unit_t *cp; 15537c478bd9Sstevel@tonic-gate int is_present; 15547c478bd9Sstevel@tonic-gate int is_attached; 15557c478bd9Sstevel@tonic-gate 15567c478bd9Sstevel@tonic-gate cp = &dp->du_common; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate /* check if the user requested this device */ 15597c478bd9Sstevel@tonic-gate if ((uset & (1 << cp->sbdev_unum)) == 0) { 15607c478bd9Sstevel@tonic-gate return (0); 15617c478bd9Sstevel@tonic-gate } 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate is_present = DR_DEV_IS_PRESENT(cp) ? 1 : 0; 15647c478bd9Sstevel@tonic-gate is_attached = DR_DEV_IS_ATTACHED(cp) ? 1 : 0; 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate /* 15677c478bd9Sstevel@tonic-gate * If the present_only flag is set, a valid target 15687c478bd9Sstevel@tonic-gate * must be present but not attached. Otherwise, it 15697c478bd9Sstevel@tonic-gate * must be both present and attached. 15707c478bd9Sstevel@tonic-gate */ 15717c478bd9Sstevel@tonic-gate if (is_present && (present_only ^ is_attached)) { 15727c478bd9Sstevel@tonic-gate /* sanity check */ 15737c478bd9Sstevel@tonic-gate ASSERT(cp->sbdev_id != (drmachid_t)0); 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate return (1); 15767c478bd9Sstevel@tonic-gate } 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate return (0); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate 15817c478bd9Sstevel@tonic-gate static void 15827c478bd9Sstevel@tonic-gate dr_dev_make_list(dr_handle_t *hp, sbd_comp_type_t type, int present_only, 15837c478bd9Sstevel@tonic-gate dr_common_unit_t ***devlist, int *devnum) 15847c478bd9Sstevel@tonic-gate { 15857c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 15867c478bd9Sstevel@tonic-gate int unum; 15877c478bd9Sstevel@tonic-gate int nunits; 15887c478bd9Sstevel@tonic-gate uint_t uset; 15897c478bd9Sstevel@tonic-gate int len; 15907c478bd9Sstevel@tonic-gate dr_common_unit_t **list, **wp; 15917c478bd9Sstevel@tonic-gate 15927c478bd9Sstevel@tonic-gate switch (type) { 15937c478bd9Sstevel@tonic-gate case SBD_COMP_CPU: 15947c478bd9Sstevel@tonic-gate nunits = MAX_CPU_UNITS_PER_BOARD; 15957c478bd9Sstevel@tonic-gate break; 15967c478bd9Sstevel@tonic-gate case SBD_COMP_MEM: 15977c478bd9Sstevel@tonic-gate nunits = MAX_MEM_UNITS_PER_BOARD; 15987c478bd9Sstevel@tonic-gate break; 15997c478bd9Sstevel@tonic-gate case SBD_COMP_IO: 16007c478bd9Sstevel@tonic-gate nunits = MAX_IO_UNITS_PER_BOARD; 16017c478bd9Sstevel@tonic-gate break; 16027c478bd9Sstevel@tonic-gate default: 16037c478bd9Sstevel@tonic-gate /* catch this in debug kernels */ 16047c478bd9Sstevel@tonic-gate ASSERT(0); 16057c478bd9Sstevel@tonic-gate break; 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate 16087c478bd9Sstevel@tonic-gate /* allocate list storage. */ 16097c478bd9Sstevel@tonic-gate len = sizeof (dr_common_unit_t *) * (nunits + 1); 16107c478bd9Sstevel@tonic-gate list = kmem_zalloc(len, KM_SLEEP); 16117c478bd9Sstevel@tonic-gate 16127c478bd9Sstevel@tonic-gate /* record length of storage in first element */ 161304580fdfSmathue *list++ = (dr_common_unit_t *)(uintptr_t)len; 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate /* get bit array signifying which units are to be involved */ 16167c478bd9Sstevel@tonic-gate uset = DEVSET_GET_UNITSET(hp->h_devset, type); 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate /* 16197c478bd9Sstevel@tonic-gate * Adjust the loop count for CPU devices since all cores 16207c478bd9Sstevel@tonic-gate * in a CMP will be examined in a single iteration. 16217c478bd9Sstevel@tonic-gate */ 16227c478bd9Sstevel@tonic-gate if (type == SBD_COMP_CPU) { 16237c478bd9Sstevel@tonic-gate nunits = MAX_CMP_UNITS_PER_BOARD; 16247c478bd9Sstevel@tonic-gate } 16257c478bd9Sstevel@tonic-gate 16267c478bd9Sstevel@tonic-gate /* populate list */ 16277c478bd9Sstevel@tonic-gate for (wp = list, unum = 0; unum < nunits; unum++) { 16287c478bd9Sstevel@tonic-gate 16297c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 16307c478bd9Sstevel@tonic-gate int core; 16317c478bd9Sstevel@tonic-gate int cunum; 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, type, unum); 16347c478bd9Sstevel@tonic-gate if (dr_dev_is_target(dp, present_only, uset)) { 16357c478bd9Sstevel@tonic-gate *wp++ = &dp->du_common; 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate /* further processing is only required for CPUs */ 16397c478bd9Sstevel@tonic-gate if (type != SBD_COMP_CPU) { 16407c478bd9Sstevel@tonic-gate continue; 16417c478bd9Sstevel@tonic-gate } 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate /* 16447c478bd9Sstevel@tonic-gate * Add any additional cores from the current CPU 16457c478bd9Sstevel@tonic-gate * device. This is to ensure that all the cores 16467c478bd9Sstevel@tonic-gate * are grouped together in the device list, and 16477c478bd9Sstevel@tonic-gate * consequently sequenced together during the actual 16487c478bd9Sstevel@tonic-gate * operation. 16497c478bd9Sstevel@tonic-gate */ 16507c478bd9Sstevel@tonic-gate for (core = 1; core < MAX_CORES_PER_CMP; core++) { 16517c478bd9Sstevel@tonic-gate 16527c478bd9Sstevel@tonic-gate cunum = DR_CMP_CORE_UNUM(unum, core); 16537c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, type, cunum); 16547c478bd9Sstevel@tonic-gate 16557c478bd9Sstevel@tonic-gate if (dr_dev_is_target(dp, present_only, uset)) { 16567c478bd9Sstevel@tonic-gate *wp++ = &dp->du_common; 16577c478bd9Sstevel@tonic-gate } 16587c478bd9Sstevel@tonic-gate } 16597c478bd9Sstevel@tonic-gate } 16607c478bd9Sstevel@tonic-gate 16617c478bd9Sstevel@tonic-gate /* calculate number of units in list, return result and list pointer */ 16627c478bd9Sstevel@tonic-gate *devnum = wp - list; 16637c478bd9Sstevel@tonic-gate *devlist = list; 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate static void 16677c478bd9Sstevel@tonic-gate dr_dev_clean_up(dr_handle_t *hp, dr_common_unit_t **list, int devnum) 16687c478bd9Sstevel@tonic-gate { 16697c478bd9Sstevel@tonic-gate int len; 16707c478bd9Sstevel@tonic-gate int n = 0; 16717c478bd9Sstevel@tonic-gate dr_common_unit_t *cp, **rp = list; 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate /* 16747c478bd9Sstevel@tonic-gate * move first encountered unit error to handle if handle 16757c478bd9Sstevel@tonic-gate * does not yet have a recorded error. 16767c478bd9Sstevel@tonic-gate */ 16777c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) { 16787c478bd9Sstevel@tonic-gate while (n++ < devnum) { 16797c478bd9Sstevel@tonic-gate cp = *rp++; 16807c478bd9Sstevel@tonic-gate if (cp->sbdev_error != NULL) { 16817c478bd9Sstevel@tonic-gate hp->h_err = cp->sbdev_error; 16827c478bd9Sstevel@tonic-gate cp->sbdev_error = NULL; 16837c478bd9Sstevel@tonic-gate break; 16847c478bd9Sstevel@tonic-gate } 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate } 16877c478bd9Sstevel@tonic-gate 16887c478bd9Sstevel@tonic-gate /* free remaining unit errors */ 16897c478bd9Sstevel@tonic-gate while (n++ < devnum) { 16907c478bd9Sstevel@tonic-gate cp = *rp++; 16917c478bd9Sstevel@tonic-gate if (cp->sbdev_error != NULL) { 16927c478bd9Sstevel@tonic-gate sbd_err_clear(&cp->sbdev_error); 16937c478bd9Sstevel@tonic-gate cp->sbdev_error = NULL; 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate } 16967c478bd9Sstevel@tonic-gate 16977c478bd9Sstevel@tonic-gate /* free list */ 16987c478bd9Sstevel@tonic-gate list -= 1; 169904580fdfSmathue len = (int)(uintptr_t)list[0]; 17007c478bd9Sstevel@tonic-gate kmem_free(list, len); 17017c478bd9Sstevel@tonic-gate } 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate static int 17047c478bd9Sstevel@tonic-gate dr_dev_walk(dr_handle_t *hp, sbd_comp_type_t type, int present_only, 17057c478bd9Sstevel@tonic-gate int (*pre_op)(dr_handle_t *, dr_common_unit_t **, int), 17067c478bd9Sstevel@tonic-gate void (*op)(dr_handle_t *, dr_common_unit_t *), 17077c478bd9Sstevel@tonic-gate int (*post_op)(dr_handle_t *, dr_common_unit_t **, int), 17087c478bd9Sstevel@tonic-gate void (*board_op)(dr_handle_t *, dr_common_unit_t **, int)) 17097c478bd9Sstevel@tonic-gate { 17107c478bd9Sstevel@tonic-gate int devnum, rv; 17117c478bd9Sstevel@tonic-gate dr_common_unit_t **devlist; 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate dr_dev_make_list(hp, type, present_only, &devlist, &devnum); 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate rv = 0; 17167c478bd9Sstevel@tonic-gate if (devnum > 0) { 17177c478bd9Sstevel@tonic-gate rv = (*pre_op)(hp, devlist, devnum); 17187c478bd9Sstevel@tonic-gate if (rv == 0) { 17197c478bd9Sstevel@tonic-gate int n; 17207c478bd9Sstevel@tonic-gate 17217c478bd9Sstevel@tonic-gate for (n = 0; n < devnum; n++) 17227c478bd9Sstevel@tonic-gate (*op)(hp, devlist[n]); 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate rv = (*post_op)(hp, devlist, devnum); 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate (*board_op)(hp, devlist, devnum); 17277c478bd9Sstevel@tonic-gate } 17287c478bd9Sstevel@tonic-gate } 17297c478bd9Sstevel@tonic-gate 17307c478bd9Sstevel@tonic-gate dr_dev_clean_up(hp, devlist, devnum); 17317c478bd9Sstevel@tonic-gate return (rv); 17327c478bd9Sstevel@tonic-gate } 17337c478bd9Sstevel@tonic-gate 17347c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17357c478bd9Sstevel@tonic-gate static int 17367c478bd9Sstevel@tonic-gate dr_dev_noop(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum) 17377c478bd9Sstevel@tonic-gate { 17387c478bd9Sstevel@tonic-gate return (0); 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate static void 17427c478bd9Sstevel@tonic-gate dr_attach_update_state(dr_handle_t *hp, 17437c478bd9Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 17447c478bd9Sstevel@tonic-gate { 17457c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 17467c478bd9Sstevel@tonic-gate int i; 17477c478bd9Sstevel@tonic-gate dr_devset_t devs_unattached, devs_present; 17487c478bd9Sstevel@tonic-gate static fn_t f = "dr_post_attach_devlist"; 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate for (i = 0; i < devnum; i++) { 17517c478bd9Sstevel@tonic-gate dr_common_unit_t *cp = devlist[i]; 17527c478bd9Sstevel@tonic-gate 17537c478bd9Sstevel@tonic-gate if (dr_check_unit_attached(cp) == -1) { 17547c478bd9Sstevel@tonic-gate PR_ALL("%s: ERROR %s not attached\n", 17557c478bd9Sstevel@tonic-gate f, cp->sbdev_path); 17567c478bd9Sstevel@tonic-gate continue; 17577c478bd9Sstevel@tonic-gate } 17587c478bd9Sstevel@tonic-gate 17597c478bd9Sstevel@tonic-gate DR_DEV_SET_ATTACHED(cp); 17607c478bd9Sstevel@tonic-gate 17617c478bd9Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_CONFIGURED); 17627c478bd9Sstevel@tonic-gate cp->sbdev_cond = SBD_COND_OK; 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate devs_present = DR_DEVS_PRESENT(bp); 17667c478bd9Sstevel@tonic-gate devs_unattached = DR_DEVS_UNATTACHED(bp); 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate switch (bp->b_state) { 17697c478bd9Sstevel@tonic-gate case DR_STATE_CONNECTED: 17707c478bd9Sstevel@tonic-gate case DR_STATE_UNCONFIGURED: 17717c478bd9Sstevel@tonic-gate ASSERT(devs_present); 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate if (devs_unattached == 0) { 17747c478bd9Sstevel@tonic-gate /* 17757c478bd9Sstevel@tonic-gate * All devices finally attached. 17767c478bd9Sstevel@tonic-gate */ 17777c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 17787c478bd9Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 17797c478bd9Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 17807c478bd9Sstevel@tonic-gate hp->h_bd->b_cond = SBD_COND_OK; 17817c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 0; 17827c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 17837c478bd9Sstevel@tonic-gate } else if (devs_present != devs_unattached) { 17847c478bd9Sstevel@tonic-gate /* 17857c478bd9Sstevel@tonic-gate * Only some devices are fully attached. 17867c478bd9Sstevel@tonic-gate */ 17877c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 17887c478bd9Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 17897c478bd9Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 17907c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 17917c478bd9Sstevel@tonic-gate } 17927c478bd9Sstevel@tonic-gate break; 17937c478bd9Sstevel@tonic-gate 17947c478bd9Sstevel@tonic-gate case DR_STATE_PARTIAL: 17957c478bd9Sstevel@tonic-gate ASSERT(devs_present); 17967c478bd9Sstevel@tonic-gate /* 17977c478bd9Sstevel@tonic-gate * All devices finally attached. 17987c478bd9Sstevel@tonic-gate */ 17997c478bd9Sstevel@tonic-gate if (devs_unattached == 0) { 18007c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 18017c478bd9Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 18027c478bd9Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 18037c478bd9Sstevel@tonic-gate hp->h_bd->b_cond = SBD_COND_OK; 18047c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 0; 18057c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate break; 18087c478bd9Sstevel@tonic-gate 18097c478bd9Sstevel@tonic-gate default: 18107c478bd9Sstevel@tonic-gate break; 18117c478bd9Sstevel@tonic-gate } 18127c478bd9Sstevel@tonic-gate } 18137c478bd9Sstevel@tonic-gate 18147c478bd9Sstevel@tonic-gate static void 18157c478bd9Sstevel@tonic-gate dr_dev_configure(dr_handle_t *hp) 18167c478bd9Sstevel@tonic-gate { 18177c478bd9Sstevel@tonic-gate int rv; 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_CPU, 1, 18207c478bd9Sstevel@tonic-gate dr_pre_attach_cpu, 18217c478bd9Sstevel@tonic-gate dr_attach_cpu, 18227c478bd9Sstevel@tonic-gate dr_post_attach_cpu, 18237c478bd9Sstevel@tonic-gate dr_attach_update_state); 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate if (rv >= 0) { 18267c478bd9Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_MEM, 1, 18277c478bd9Sstevel@tonic-gate dr_pre_attach_mem, 18287c478bd9Sstevel@tonic-gate dr_attach_mem, 18297c478bd9Sstevel@tonic-gate dr_post_attach_mem, 18307c478bd9Sstevel@tonic-gate dr_attach_update_state); 18317c478bd9Sstevel@tonic-gate } 18327c478bd9Sstevel@tonic-gate 18337c478bd9Sstevel@tonic-gate if (rv >= 0) { 18347c478bd9Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_IO, 1, 18357c478bd9Sstevel@tonic-gate dr_pre_attach_io, 18367c478bd9Sstevel@tonic-gate dr_attach_io, 18377c478bd9Sstevel@tonic-gate dr_post_attach_io, 18387c478bd9Sstevel@tonic-gate dr_attach_update_state); 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate 18427c478bd9Sstevel@tonic-gate static void 18437c478bd9Sstevel@tonic-gate dr_release_update_state(dr_handle_t *hp, 18447c478bd9Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 18457c478bd9Sstevel@tonic-gate { 18467c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(devlist)) 18477c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(devnum)) 18487c478bd9Sstevel@tonic-gate 18497c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 18507c478bd9Sstevel@tonic-gate 18517c478bd9Sstevel@tonic-gate /* 18527c478bd9Sstevel@tonic-gate * If the entire board was released and all components 18537c478bd9Sstevel@tonic-gate * unreferenced then transfer it to the UNREFERENCED state. 18547c478bd9Sstevel@tonic-gate */ 18557c478bd9Sstevel@tonic-gate if ((bp->b_state != DR_STATE_RELEASE) && 18567c478bd9Sstevel@tonic-gate (DR_DEVS_RELEASED(bp) == DR_DEVS_ATTACHED(bp))) { 18577c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_RELEASE); 18587c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 1; 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate } 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate /* called by dr_release_done [below] and dr_release_mem_done [dr_mem.c] */ 18637c478bd9Sstevel@tonic-gate int 18647c478bd9Sstevel@tonic-gate dr_release_dev_done(dr_common_unit_t *cp) 18657c478bd9Sstevel@tonic-gate { 18667c478bd9Sstevel@tonic-gate if (cp->sbdev_state == DR_STATE_RELEASE) { 18677c478bd9Sstevel@tonic-gate ASSERT(DR_DEV_IS_RELEASED(cp)); 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate DR_DEV_SET_UNREFERENCED(cp); 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_UNREFERENCED); 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate return (0); 18747c478bd9Sstevel@tonic-gate } else { 18757c478bd9Sstevel@tonic-gate return (-1); 18767c478bd9Sstevel@tonic-gate } 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate 18797c478bd9Sstevel@tonic-gate static void 18807c478bd9Sstevel@tonic-gate dr_release_done(dr_handle_t *hp, dr_common_unit_t *cp) 18817c478bd9Sstevel@tonic-gate { 18827c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(hp)) 18837c478bd9Sstevel@tonic-gate 18847c478bd9Sstevel@tonic-gate dr_board_t *bp; 18857c478bd9Sstevel@tonic-gate static fn_t f = "dr_release_done"; 18867c478bd9Sstevel@tonic-gate 18877c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 18887c478bd9Sstevel@tonic-gate 18897c478bd9Sstevel@tonic-gate /* get board pointer & sanity check */ 18907c478bd9Sstevel@tonic-gate bp = cp->sbdev_bp; 18917c478bd9Sstevel@tonic-gate ASSERT(bp == hp->h_bd); 18927c478bd9Sstevel@tonic-gate 18937c478bd9Sstevel@tonic-gate /* 18947c478bd9Sstevel@tonic-gate * Transfer the device which just completed its release 18957c478bd9Sstevel@tonic-gate * to the UNREFERENCED state. 18967c478bd9Sstevel@tonic-gate */ 18977c478bd9Sstevel@tonic-gate switch (cp->sbdev_type) { 18987c478bd9Sstevel@tonic-gate case SBD_COMP_MEM: 18997c478bd9Sstevel@tonic-gate dr_release_mem_done(cp); 19007c478bd9Sstevel@tonic-gate break; 19017c478bd9Sstevel@tonic-gate 19027c478bd9Sstevel@tonic-gate default: 19037c478bd9Sstevel@tonic-gate DR_DEV_SET_RELEASED(cp); 19047c478bd9Sstevel@tonic-gate 19057c478bd9Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_RELEASE); 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate (void) dr_release_dev_done(cp); 19087c478bd9Sstevel@tonic-gate break; 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate 19117c478bd9Sstevel@tonic-gate /* 19127c478bd9Sstevel@tonic-gate * If we're not already in the RELEASE state for this 19137c478bd9Sstevel@tonic-gate * board and we now have released all that were previously 19147c478bd9Sstevel@tonic-gate * attached, then transfer the board to the RELEASE state. 19157c478bd9Sstevel@tonic-gate */ 19167c478bd9Sstevel@tonic-gate if ((bp->b_state == DR_STATE_RELEASE) && 19177c478bd9Sstevel@tonic-gate (DR_DEVS_RELEASED(bp) == DR_DEVS_UNREFERENCED(bp))) { 19187c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_UNREFERENCED); 19197c478bd9Sstevel@tonic-gate bp->b_busy = 1; 19207c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate } 19237c478bd9Sstevel@tonic-gate 19247c478bd9Sstevel@tonic-gate static void 19257c478bd9Sstevel@tonic-gate dr_dev_release_mem(dr_handle_t *hp, dr_common_unit_t *dv) 19267c478bd9Sstevel@tonic-gate { 19277c478bd9Sstevel@tonic-gate dr_release_mem(dv); 19287c478bd9Sstevel@tonic-gate dr_release_done(hp, dv); 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate static void 19327c478bd9Sstevel@tonic-gate dr_dev_release(dr_handle_t *hp) 19337c478bd9Sstevel@tonic-gate { 19347c478bd9Sstevel@tonic-gate int rv; 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 1; 19377c478bd9Sstevel@tonic-gate 19387c478bd9Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_CPU, 0, 19397c478bd9Sstevel@tonic-gate dr_pre_release_cpu, 19407c478bd9Sstevel@tonic-gate dr_release_done, 19417c478bd9Sstevel@tonic-gate dr_dev_noop, 19427c478bd9Sstevel@tonic-gate dr_release_update_state); 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate if (rv >= 0) { 19457c478bd9Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_MEM, 0, 19467c478bd9Sstevel@tonic-gate dr_pre_release_mem, 19477c478bd9Sstevel@tonic-gate dr_dev_release_mem, 19487c478bd9Sstevel@tonic-gate dr_dev_noop, 19497c478bd9Sstevel@tonic-gate dr_release_update_state); 19507c478bd9Sstevel@tonic-gate } 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate if (rv >= 0) { 19537c478bd9Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_IO, 0, 19547c478bd9Sstevel@tonic-gate dr_pre_release_io, 19557c478bd9Sstevel@tonic-gate dr_release_done, 19567c478bd9Sstevel@tonic-gate dr_dev_noop, 19577c478bd9Sstevel@tonic-gate dr_release_update_state); 19587c478bd9Sstevel@tonic-gate 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate 19617c478bd9Sstevel@tonic-gate if (rv < 0) 19627c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 0; 19637c478bd9Sstevel@tonic-gate /* else, b_busy will be cleared in dr_detach_update_state() */ 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate static void 19677c478bd9Sstevel@tonic-gate dr_detach_update_state(dr_handle_t *hp, 19687c478bd9Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 19697c478bd9Sstevel@tonic-gate { 19707c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 19717c478bd9Sstevel@tonic-gate int i; 19727c478bd9Sstevel@tonic-gate dr_state_t bstate; 19737c478bd9Sstevel@tonic-gate static fn_t f = "dr_detach_update_state"; 19747c478bd9Sstevel@tonic-gate 19757c478bd9Sstevel@tonic-gate for (i = 0; i < devnum; i++) { 19767c478bd9Sstevel@tonic-gate dr_common_unit_t *cp = devlist[i]; 19777c478bd9Sstevel@tonic-gate 19787c478bd9Sstevel@tonic-gate if (dr_check_unit_attached(cp) >= 0) { 19797c478bd9Sstevel@tonic-gate /* 19807c478bd9Sstevel@tonic-gate * Device is still attached probably due 19817c478bd9Sstevel@tonic-gate * to an error. Need to keep track of it. 19827c478bd9Sstevel@tonic-gate */ 19837c478bd9Sstevel@tonic-gate PR_ALL("%s: ERROR %s not detached\n", 19847c478bd9Sstevel@tonic-gate f, cp->sbdev_path); 19857c478bd9Sstevel@tonic-gate 19867c478bd9Sstevel@tonic-gate continue; 19877c478bd9Sstevel@tonic-gate } 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate DR_DEV_CLR_ATTACHED(cp); 19907c478bd9Sstevel@tonic-gate DR_DEV_CLR_RELEASED(cp); 19917c478bd9Sstevel@tonic-gate DR_DEV_CLR_UNREFERENCED(cp); 19927c478bd9Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_UNCONFIGURED); 19937c478bd9Sstevel@tonic-gate } 19947c478bd9Sstevel@tonic-gate 19957c478bd9Sstevel@tonic-gate bstate = bp->b_state; 19967c478bd9Sstevel@tonic-gate if (bstate != DR_STATE_UNCONFIGURED) { 19977c478bd9Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp) == DR_DEVS_UNATTACHED(bp)) { 19987c478bd9Sstevel@tonic-gate /* 19997c478bd9Sstevel@tonic-gate * All devices are finally detached. 20007c478bd9Sstevel@tonic-gate */ 20017c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_UNCONFIGURED); 20027c478bd9Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_UNCONFIGURED; 20037c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 20047c478bd9Sstevel@tonic-gate } else if ((bp->b_state != DR_STATE_PARTIAL) && 20057c478bd9Sstevel@tonic-gate (DR_DEVS_ATTACHED(bp) != 20067c478bd9Sstevel@tonic-gate DR_DEVS_PRESENT(bp))) { 20077c478bd9Sstevel@tonic-gate /* 20087c478bd9Sstevel@tonic-gate * Some devices remain attached. 20097c478bd9Sstevel@tonic-gate */ 20107c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 20117c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate 20147c478bd9Sstevel@tonic-gate if ((hp->h_devset & DR_DEVS_UNATTACHED(bp)) == hp->h_devset) 20157c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 0; 20167c478bd9Sstevel@tonic-gate } 20177c478bd9Sstevel@tonic-gate } 20187c478bd9Sstevel@tonic-gate 20197c478bd9Sstevel@tonic-gate static int 20207c478bd9Sstevel@tonic-gate dr_dev_unconfigure(dr_handle_t *hp) 20217c478bd9Sstevel@tonic-gate { 20227c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate /* 20257c478bd9Sstevel@tonic-gate * Block out status during IO unconfig. 20267c478bd9Sstevel@tonic-gate */ 20277c478bd9Sstevel@tonic-gate mutex_enter(&bp->b_slock); 20287c478bd9Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 20297c478bd9Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 20307c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 20317c478bd9Sstevel@tonic-gate return (EINTR); 20327c478bd9Sstevel@tonic-gate } 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 20357c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 20367c478bd9Sstevel@tonic-gate 20377c478bd9Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_IO, 0, 20387c478bd9Sstevel@tonic-gate dr_pre_detach_io, 20397c478bd9Sstevel@tonic-gate dr_detach_io, 20407c478bd9Sstevel@tonic-gate dr_post_detach_io, 20417c478bd9Sstevel@tonic-gate dr_detach_update_state); 20427c478bd9Sstevel@tonic-gate 20437c478bd9Sstevel@tonic-gate dr_unlock_status(bp); 20447c478bd9Sstevel@tonic-gate 20457c478bd9Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_CPU, 0, 20467c478bd9Sstevel@tonic-gate dr_pre_detach_cpu, 20477c478bd9Sstevel@tonic-gate dr_detach_cpu, 20487c478bd9Sstevel@tonic-gate dr_post_detach_cpu, 20497c478bd9Sstevel@tonic-gate dr_detach_update_state); 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_MEM, 0, 20527c478bd9Sstevel@tonic-gate dr_pre_detach_mem, 20537c478bd9Sstevel@tonic-gate dr_detach_mem, 20547c478bd9Sstevel@tonic-gate dr_post_detach_mem, 20557c478bd9Sstevel@tonic-gate dr_detach_update_state); 20567c478bd9Sstevel@tonic-gate 20577c478bd9Sstevel@tonic-gate return (0); 20587c478bd9Sstevel@tonic-gate } 20597c478bd9Sstevel@tonic-gate 20607c478bd9Sstevel@tonic-gate static void 20617c478bd9Sstevel@tonic-gate dr_dev_cancel(dr_handle_t *hp) 20627c478bd9Sstevel@tonic-gate { 20637c478bd9Sstevel@tonic-gate int i; 20647c478bd9Sstevel@tonic-gate dr_devset_t devset; 20657c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 20667c478bd9Sstevel@tonic-gate static fn_t f = "dr_dev_cancel"; 20677c478bd9Sstevel@tonic-gate 20687c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 20697c478bd9Sstevel@tonic-gate 20707c478bd9Sstevel@tonic-gate /* 20717c478bd9Sstevel@tonic-gate * Only devices which have been "released" are 20727c478bd9Sstevel@tonic-gate * subject to cancellation. 20737c478bd9Sstevel@tonic-gate */ 20747c478bd9Sstevel@tonic-gate devset = hp->h_devset & DR_DEVS_RELEASED(bp); 20757c478bd9Sstevel@tonic-gate 20767c478bd9Sstevel@tonic-gate /* 20777c478bd9Sstevel@tonic-gate * Nothing to do for CPUs or IO other than change back 20787c478bd9Sstevel@tonic-gate * their state. 20797c478bd9Sstevel@tonic-gate */ 20807c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 20817c478bd9Sstevel@tonic-gate dr_cpu_unit_t *cp; 20827c478bd9Sstevel@tonic-gate dr_state_t nstate; 20837c478bd9Sstevel@tonic-gate 20847c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_CPU, i)) 20857c478bd9Sstevel@tonic-gate continue; 20867c478bd9Sstevel@tonic-gate 20877c478bd9Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 20887c478bd9Sstevel@tonic-gate if (dr_cancel_cpu(cp) == 0) 20897c478bd9Sstevel@tonic-gate nstate = DR_STATE_CONFIGURED; 20907c478bd9Sstevel@tonic-gate else 20917c478bd9Sstevel@tonic-gate nstate = DR_STATE_FATAL; 20927c478bd9Sstevel@tonic-gate 20937c478bd9Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, nstate); 20947c478bd9Sstevel@tonic-gate } 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 20977c478bd9Sstevel@tonic-gate dr_io_unit_t *ip; 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_IO, i)) 21007c478bd9Sstevel@tonic-gate continue; 21017c478bd9Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 21027c478bd9Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_CONFIGURED); 21037c478bd9Sstevel@tonic-gate } 21047c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 21057c478bd9Sstevel@tonic-gate dr_mem_unit_t *mp; 21067c478bd9Sstevel@tonic-gate dr_state_t nstate; 21077c478bd9Sstevel@tonic-gate 21087c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_MEM, i)) 21097c478bd9Sstevel@tonic-gate continue; 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 21127c478bd9Sstevel@tonic-gate if (dr_cancel_mem(mp) == 0) 21137c478bd9Sstevel@tonic-gate nstate = DR_STATE_CONFIGURED; 21147c478bd9Sstevel@tonic-gate else 21157c478bd9Sstevel@tonic-gate nstate = DR_STATE_FATAL; 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, nstate); 21187c478bd9Sstevel@tonic-gate } 21197c478bd9Sstevel@tonic-gate 21207c478bd9Sstevel@tonic-gate PR_ALL("%s: unreleasing devset (0x%x)\n", f, (uint_t)devset); 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate DR_DEVS_CANCEL(bp, devset); 21237c478bd9Sstevel@tonic-gate 21247c478bd9Sstevel@tonic-gate if (DR_DEVS_RELEASED(bp) == 0) { 21257c478bd9Sstevel@tonic-gate dr_state_t new_state; 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * If the board no longer has any released devices 21287c478bd9Sstevel@tonic-gate * than transfer it back to the CONFIG/PARTIAL state. 21297c478bd9Sstevel@tonic-gate */ 21307c478bd9Sstevel@tonic-gate if (DR_DEVS_ATTACHED(bp) == DR_DEVS_PRESENT(bp)) 21317c478bd9Sstevel@tonic-gate new_state = DR_STATE_CONFIGURED; 21327c478bd9Sstevel@tonic-gate else 21337c478bd9Sstevel@tonic-gate new_state = DR_STATE_PARTIAL; 21347c478bd9Sstevel@tonic-gate if (bp->b_state != new_state) { 21357c478bd9Sstevel@tonic-gate dr_board_transition(bp, new_state); 21367c478bd9Sstevel@tonic-gate } 21377c478bd9Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 21387c478bd9Sstevel@tonic-gate hp->h_bd->b_busy = 0; 21397c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 21407c478bd9Sstevel@tonic-gate } 21417c478bd9Sstevel@tonic-gate } 21427c478bd9Sstevel@tonic-gate 21437c478bd9Sstevel@tonic-gate static int 21447c478bd9Sstevel@tonic-gate dr_dev_status(dr_handle_t *hp) 21457c478bd9Sstevel@tonic-gate { 21467c478bd9Sstevel@tonic-gate int nstat, mode, ncm, sz, pbsz, pnstat; 21477c478bd9Sstevel@tonic-gate dr_handle_t *shp; 21487c478bd9Sstevel@tonic-gate dr_devset_t devset = 0; 21497c478bd9Sstevel@tonic-gate sbd_stat_t *dstatp = NULL; 21507c478bd9Sstevel@tonic-gate sbd_dev_stat_t *devstatp; 21517c478bd9Sstevel@tonic-gate dr_board_t *bp; 21527c478bd9Sstevel@tonic-gate drmach_status_t pstat; 21537c478bd9Sstevel@tonic-gate int rv = 0; 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 21567c478bd9Sstevel@tonic-gate int sz32 = 0; 21577c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 21587c478bd9Sstevel@tonic-gate 21597c478bd9Sstevel@tonic-gate static fn_t f = "dr_status"; 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 21627c478bd9Sstevel@tonic-gate 21637c478bd9Sstevel@tonic-gate mode = hp->h_mode; 21647c478bd9Sstevel@tonic-gate shp = hp; 21657c478bd9Sstevel@tonic-gate devset = shp->h_devset; 21667c478bd9Sstevel@tonic-gate bp = hp->h_bd; 21677c478bd9Sstevel@tonic-gate 21687c478bd9Sstevel@tonic-gate /* 21697c478bd9Sstevel@tonic-gate * Block out disconnect, unassign, IO unconfigure and 21707c478bd9Sstevel@tonic-gate * devinfo branch creation during status. 21717c478bd9Sstevel@tonic-gate */ 21727c478bd9Sstevel@tonic-gate mutex_enter(&bp->b_slock); 21737c478bd9Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 21747c478bd9Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 21757c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 21767c478bd9Sstevel@tonic-gate return (EINTR); 21777c478bd9Sstevel@tonic-gate } 21787c478bd9Sstevel@tonic-gate } 21797c478bd9Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 21807c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 21817c478bd9Sstevel@tonic-gate 21827c478bd9Sstevel@tonic-gate ncm = 1; 21837c478bd9Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_type == SBD_COMP_NONE) { 21847c478bd9Sstevel@tonic-gate if (dr_cmd_flags(hp) & SBD_FLAG_ALLCMP) { 21857c478bd9Sstevel@tonic-gate /* 21867c478bd9Sstevel@tonic-gate * Calculate the maximum number of components possible 21877c478bd9Sstevel@tonic-gate * for a board. This number will be used to size the 21887c478bd9Sstevel@tonic-gate * status scratch buffer used by board and component 21897c478bd9Sstevel@tonic-gate * status functions. 21907c478bd9Sstevel@tonic-gate * This buffer may differ in size from what is provided 21917c478bd9Sstevel@tonic-gate * by the plugin, since the known component set on the 21927c478bd9Sstevel@tonic-gate * board may change between the plugin's GETNCM call, and 21937c478bd9Sstevel@tonic-gate * the status call. Sizing will be adjusted to the plugin's 21947c478bd9Sstevel@tonic-gate * receptacle buffer at copyout time. 21957c478bd9Sstevel@tonic-gate */ 21967c478bd9Sstevel@tonic-gate ncm = MAX_CPU_UNITS_PER_BOARD + 21977c478bd9Sstevel@tonic-gate MAX_MEM_UNITS_PER_BOARD + 21987c478bd9Sstevel@tonic-gate MAX_IO_UNITS_PER_BOARD; 21997c478bd9Sstevel@tonic-gate 22007c478bd9Sstevel@tonic-gate } else { 22017c478bd9Sstevel@tonic-gate /* 22027c478bd9Sstevel@tonic-gate * In the case of c_type == SBD_COMP_NONE, and 22037c478bd9Sstevel@tonic-gate * SBD_FLAG_ALLCMP not specified, only the board 22047c478bd9Sstevel@tonic-gate * info is to be returned, no components. 22057c478bd9Sstevel@tonic-gate */ 22067c478bd9Sstevel@tonic-gate ncm = 0; 22077c478bd9Sstevel@tonic-gate devset = 0; 22087c478bd9Sstevel@tonic-gate } 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate sz = sizeof (sbd_stat_t); 22127c478bd9Sstevel@tonic-gate if (ncm > 1) 22137c478bd9Sstevel@tonic-gate sz += sizeof (sbd_dev_stat_t) * (ncm - 1); 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate 22167c478bd9Sstevel@tonic-gate pbsz = (int)hp->h_sbdcmd.cmd_stat.s_nbytes; 22177c478bd9Sstevel@tonic-gate pnstat = (pbsz - sizeof (sbd_stat_t))/sizeof (sbd_dev_stat_t); 22187c478bd9Sstevel@tonic-gate 22197c478bd9Sstevel@tonic-gate /* 22207c478bd9Sstevel@tonic-gate * s_nbytes describes the size of the preallocated user 22217c478bd9Sstevel@tonic-gate * buffer into which the application is execting to 22227c478bd9Sstevel@tonic-gate * receive the sbd_stat_t and sbd_dev_stat_t structures. 22237c478bd9Sstevel@tonic-gate */ 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate /* 22287c478bd9Sstevel@tonic-gate * More buffer space is required for the 64bit to 32bit 22297c478bd9Sstevel@tonic-gate * conversion of data structures. 22307c478bd9Sstevel@tonic-gate */ 22317c478bd9Sstevel@tonic-gate if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) { 22327c478bd9Sstevel@tonic-gate sz32 = sizeof (sbd_stat32_t); 22337c478bd9Sstevel@tonic-gate if (ncm > 1) 22347c478bd9Sstevel@tonic-gate sz32 += sizeof (sbd_dev_stat32_t) * (ncm - 1); 22357c478bd9Sstevel@tonic-gate pnstat = (pbsz - sizeof (sbd_stat32_t))/ 22367c478bd9Sstevel@tonic-gate sizeof (sbd_dev_stat32_t); 22377c478bd9Sstevel@tonic-gate } 22387c478bd9Sstevel@tonic-gate 22397c478bd9Sstevel@tonic-gate sz += sz32; 22407c478bd9Sstevel@tonic-gate #endif 22417c478bd9Sstevel@tonic-gate /* 22427c478bd9Sstevel@tonic-gate * Since one sbd_dev_stat_t is included in the sbd_stat_t, 22437c478bd9Sstevel@tonic-gate * increment the plugin's nstat count. 22447c478bd9Sstevel@tonic-gate */ 22457c478bd9Sstevel@tonic-gate ++pnstat; 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate if (bp->b_id == 0) { 22487c478bd9Sstevel@tonic-gate bzero(&pstat, sizeof (pstat)); 22497c478bd9Sstevel@tonic-gate } else { 22507c478bd9Sstevel@tonic-gate sbd_error_t *err; 22517c478bd9Sstevel@tonic-gate 22527c478bd9Sstevel@tonic-gate err = drmach_status(bp->b_id, &pstat); 22537c478bd9Sstevel@tonic-gate if (err) { 22547c478bd9Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &err); 22557c478bd9Sstevel@tonic-gate rv = EIO; 22567c478bd9Sstevel@tonic-gate goto status_done; 22577c478bd9Sstevel@tonic-gate } 22587c478bd9Sstevel@tonic-gate } 22597c478bd9Sstevel@tonic-gate 22607c478bd9Sstevel@tonic-gate dstatp = (sbd_stat_t *)GETSTRUCT(char, sz); 22617c478bd9Sstevel@tonic-gate 22627c478bd9Sstevel@tonic-gate devstatp = &dstatp->s_stat[0]; 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate dstatp->s_board = bp->b_num; 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate /* 22677c478bd9Sstevel@tonic-gate * Detect transitions between empty and disconnected. 22687c478bd9Sstevel@tonic-gate */ 22697c478bd9Sstevel@tonic-gate if (!pstat.empty && (bp->b_rstate == SBD_STAT_EMPTY)) 22707c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_DISCONNECTED; 22717c478bd9Sstevel@tonic-gate else if (pstat.empty && (bp->b_rstate == SBD_STAT_DISCONNECTED)) 22727c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate dstatp->s_rstate = bp->b_rstate; 22757c478bd9Sstevel@tonic-gate dstatp->s_ostate = bp->b_ostate; 22767c478bd9Sstevel@tonic-gate dstatp->s_cond = bp->b_cond = pstat.cond; 22777c478bd9Sstevel@tonic-gate dstatp->s_busy = bp->b_busy | pstat.busy; 22787c478bd9Sstevel@tonic-gate dstatp->s_time = bp->b_time; 22797c478bd9Sstevel@tonic-gate dstatp->s_power = pstat.powered; 22807c478bd9Sstevel@tonic-gate dstatp->s_assigned = bp->b_assigned = pstat.assigned; 22817c478bd9Sstevel@tonic-gate dstatp->s_nstat = nstat = 0; 22827c478bd9Sstevel@tonic-gate bcopy(&pstat.type[0], &dstatp->s_type[0], SBD_TYPE_LEN); 22837c478bd9Sstevel@tonic-gate bcopy(&pstat.info[0], &dstatp->s_info[0], SBD_MAX_INFO); 22847c478bd9Sstevel@tonic-gate 22857c478bd9Sstevel@tonic-gate devset &= DR_DEVS_PRESENT(bp); 22867c478bd9Sstevel@tonic-gate if (devset == 0) { 22877c478bd9Sstevel@tonic-gate /* 22887c478bd9Sstevel@tonic-gate * No device chosen. 22897c478bd9Sstevel@tonic-gate */ 22907c478bd9Sstevel@tonic-gate PR_ALL("%s: no device present\n", f); 22917c478bd9Sstevel@tonic-gate } 22927c478bd9Sstevel@tonic-gate 22937c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT)) 22947c478bd9Sstevel@tonic-gate if ((nstat = dr_cpu_status(hp, devset, devstatp)) > 0) { 22957c478bd9Sstevel@tonic-gate dstatp->s_nstat += nstat; 22967c478bd9Sstevel@tonic-gate devstatp += nstat; 22977c478bd9Sstevel@tonic-gate } 22987c478bd9Sstevel@tonic-gate 22997c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT)) 23007c478bd9Sstevel@tonic-gate if ((nstat = dr_mem_status(hp, devset, devstatp)) > 0) { 23017c478bd9Sstevel@tonic-gate dstatp->s_nstat += nstat; 23027c478bd9Sstevel@tonic-gate devstatp += nstat; 23037c478bd9Sstevel@tonic-gate } 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT)) 23067c478bd9Sstevel@tonic-gate if ((nstat = dr_io_status(hp, devset, devstatp)) > 0) { 23077c478bd9Sstevel@tonic-gate dstatp->s_nstat += nstat; 23087c478bd9Sstevel@tonic-gate devstatp += nstat; 23097c478bd9Sstevel@tonic-gate } 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate /* 23127c478bd9Sstevel@tonic-gate * Due to a possible change in number of components between 23137c478bd9Sstevel@tonic-gate * the time of plugin's GETNCM call and now, there may be 23147c478bd9Sstevel@tonic-gate * more or less components than the plugin's buffer can 23157c478bd9Sstevel@tonic-gate * hold. Adjust s_nstat accordingly. 23167c478bd9Sstevel@tonic-gate */ 23177c478bd9Sstevel@tonic-gate 23187c478bd9Sstevel@tonic-gate dstatp->s_nstat = dstatp->s_nstat > pnstat ? pnstat : dstatp->s_nstat; 23197c478bd9Sstevel@tonic-gate 23207c478bd9Sstevel@tonic-gate 23217c478bd9Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 23227c478bd9Sstevel@tonic-gate if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) { 23237c478bd9Sstevel@tonic-gate int i, j; 23247c478bd9Sstevel@tonic-gate sbd_stat32_t *dstat32p; 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate dstat32p = (sbd_stat32_t *)devstatp; 23277c478bd9Sstevel@tonic-gate 23287c478bd9Sstevel@tonic-gate /* Alignment Paranoia */ 23297c478bd9Sstevel@tonic-gate if ((ulong_t)dstat32p & 0x1) { 233004580fdfSmathue PR_ALL("%s: alignment: sz=0x%lx dstat32p=0x%p\n", 233107d06da5SSurya Prakki f, sizeof (sbd_stat32_t), (void *)dstat32p); 23327c478bd9Sstevel@tonic-gate DR_OP_INTERNAL_ERROR(hp); 23337c478bd9Sstevel@tonic-gate rv = EINVAL; 23347c478bd9Sstevel@tonic-gate goto status_done; 23357c478bd9Sstevel@tonic-gate } 23367c478bd9Sstevel@tonic-gate 23377c478bd9Sstevel@tonic-gate /* paranoia: detect buffer overrun */ 23387c478bd9Sstevel@tonic-gate if ((caddr_t)&dstat32p->s_stat[dstatp->s_nstat] > 23397c478bd9Sstevel@tonic-gate ((caddr_t)dstatp) + sz) { 23407c478bd9Sstevel@tonic-gate DR_OP_INTERNAL_ERROR(hp); 23417c478bd9Sstevel@tonic-gate rv = EINVAL; 23427c478bd9Sstevel@tonic-gate goto status_done; 23437c478bd9Sstevel@tonic-gate } 23447c478bd9Sstevel@tonic-gate 23457c478bd9Sstevel@tonic-gate /* copy sbd_stat_t structure members */ 23467c478bd9Sstevel@tonic-gate #define _SBD_STAT(t, m) dstat32p->m = (t)dstatp->m 23477c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_board); 23487c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_rstate); 23497c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_ostate); 23507c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_cond); 23517c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_busy); 23527c478bd9Sstevel@tonic-gate _SBD_STAT(time32_t, s_time); 23537c478bd9Sstevel@tonic-gate _SBD_STAT(uint32_t, s_power); 23547c478bd9Sstevel@tonic-gate _SBD_STAT(uint32_t, s_assigned); 23557c478bd9Sstevel@tonic-gate _SBD_STAT(int32_t, s_nstat); 23567c478bd9Sstevel@tonic-gate bcopy(&dstatp->s_type[0], &dstat32p->s_type[0], 23577c478bd9Sstevel@tonic-gate SBD_TYPE_LEN); 23587c478bd9Sstevel@tonic-gate bcopy(&dstatp->s_info[0], &dstat32p->s_info[0], 23597c478bd9Sstevel@tonic-gate SBD_MAX_INFO); 23607c478bd9Sstevel@tonic-gate #undef _SBD_STAT 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate for (i = 0; i < dstatp->s_nstat; i++) { 23637c478bd9Sstevel@tonic-gate sbd_dev_stat_t *dsp = &dstatp->s_stat[i]; 23647c478bd9Sstevel@tonic-gate sbd_dev_stat32_t *ds32p = &dstat32p->s_stat[i]; 23657c478bd9Sstevel@tonic-gate #define _SBD_DEV_STAT(t, m) ds32p->m = (t)dsp->m 23667c478bd9Sstevel@tonic-gate 23677c478bd9Sstevel@tonic-gate /* copy sbd_cm_stat_t structure members */ 23687c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_type); 23697c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_unit); 23707c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_ostate); 23717c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_cond); 23727c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_busy); 23737c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_suspend); 23747c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(time32_t, ds_time); 23757c478bd9Sstevel@tonic-gate bcopy(&dsp->ds_name[0], &ds32p->ds_name[0], 23767c478bd9Sstevel@tonic-gate OBP_MAXPROPNAME); 23777c478bd9Sstevel@tonic-gate 23787c478bd9Sstevel@tonic-gate switch (dsp->ds_type) { 23797c478bd9Sstevel@tonic-gate case SBD_COMP_CPU: 23807c478bd9Sstevel@tonic-gate /* copy sbd_cpu_stat_t structure members */ 23817c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_isbootproc); 23827c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_cpuid); 23837c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_speed); 23847c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_ecache); 23857c478bd9Sstevel@tonic-gate break; 23867c478bd9Sstevel@tonic-gate 23877c478bd9Sstevel@tonic-gate case SBD_COMP_MEM: 23887c478bd9Sstevel@tonic-gate /* copy sbd_mem_stat_t structure members */ 23897c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_interleave); 23907c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_basepfn); 23917c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_totpages); 23927c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_detpages); 23937c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_pageslost); 23947c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_managed_pages); 23957c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_pages); 23967c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_first); 23977c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_last); 23987c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_cage_enabled); 23997c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_peer_is_target); 24007c478bd9Sstevel@tonic-gate bcopy(&dsp->d_mem.ms_peer_ap_id[0], 24017c478bd9Sstevel@tonic-gate &ds32p->d_mem.ms_peer_ap_id[0], 24027c478bd9Sstevel@tonic-gate sizeof (ds32p->d_mem.ms_peer_ap_id)); 24037c478bd9Sstevel@tonic-gate break; 24047c478bd9Sstevel@tonic-gate 24057c478bd9Sstevel@tonic-gate case SBD_COMP_IO: 24067c478bd9Sstevel@tonic-gate /* copy sbd_io_stat_t structure members */ 24077c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_io.is_referenced); 24087c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_io.is_unsafe_count); 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate for (j = 0; j < SBD_MAX_UNSAFE; j++) 24117c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, 24127c478bd9Sstevel@tonic-gate d_io.is_unsafe_list[j]); 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate bcopy(&dsp->d_io.is_pathname[0], 24157c478bd9Sstevel@tonic-gate &ds32p->d_io.is_pathname[0], MAXPATHLEN); 24167c478bd9Sstevel@tonic-gate break; 24177c478bd9Sstevel@tonic-gate 24187c478bd9Sstevel@tonic-gate case SBD_COMP_CMP: 24197c478bd9Sstevel@tonic-gate /* copy sbd_cmp_stat_t structure members */ 24207c478bd9Sstevel@tonic-gate bcopy(&dsp->d_cmp.ps_cpuid[0], 24217c478bd9Sstevel@tonic-gate &ds32p->d_cmp.ps_cpuid[0], 24227c478bd9Sstevel@tonic-gate sizeof (ds32p->d_cmp.ps_cpuid)); 24237c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_ncores); 24247c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_speed); 24257c478bd9Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_ecache); 24267c478bd9Sstevel@tonic-gate break; 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate default: 24297c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s: unknown dev type (%d)", 24307c478bd9Sstevel@tonic-gate f, (int)dsp->ds_type); 24317c478bd9Sstevel@tonic-gate rv = EFAULT; 24327c478bd9Sstevel@tonic-gate goto status_done; 24337c478bd9Sstevel@tonic-gate } 24347c478bd9Sstevel@tonic-gate #undef _SBD_DEV_STAT 24357c478bd9Sstevel@tonic-gate } 24367c478bd9Sstevel@tonic-gate 24377c478bd9Sstevel@tonic-gate 24387c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)dstat32p, 24397c478bd9Sstevel@tonic-gate hp->h_sbdcmd.cmd_stat.s_statp, pbsz, mode) != 0) { 24407c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 24417c478bd9Sstevel@tonic-gate "%s: failed to copyout status " 24427c478bd9Sstevel@tonic-gate "for board %d", f, bp->b_num); 24437c478bd9Sstevel@tonic-gate rv = EFAULT; 24447c478bd9Sstevel@tonic-gate goto status_done; 24457c478bd9Sstevel@tonic-gate } 24467c478bd9Sstevel@tonic-gate } else 24477c478bd9Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate if (ddi_copyout((void *)dstatp, hp->h_sbdcmd.cmd_stat.s_statp, 24507c478bd9Sstevel@tonic-gate pbsz, mode) != 0) { 24517c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 24527c478bd9Sstevel@tonic-gate "%s: failed to copyout status for board %d", 24537c478bd9Sstevel@tonic-gate f, bp->b_num); 24547c478bd9Sstevel@tonic-gate rv = EFAULT; 24557c478bd9Sstevel@tonic-gate goto status_done; 24567c478bd9Sstevel@tonic-gate } 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate status_done: 24597c478bd9Sstevel@tonic-gate if (dstatp != NULL) 24607c478bd9Sstevel@tonic-gate FREESTRUCT(dstatp, char, sz); 24617c478bd9Sstevel@tonic-gate 24627c478bd9Sstevel@tonic-gate dr_unlock_status(bp); 24637c478bd9Sstevel@tonic-gate 24647c478bd9Sstevel@tonic-gate return (rv); 24657c478bd9Sstevel@tonic-gate } 24667c478bd9Sstevel@tonic-gate 24677c478bd9Sstevel@tonic-gate static int 24687c478bd9Sstevel@tonic-gate dr_get_ncm(dr_handle_t *hp) 24697c478bd9Sstevel@tonic-gate { 24707c478bd9Sstevel@tonic-gate int i; 24717c478bd9Sstevel@tonic-gate int ncm = 0; 24727c478bd9Sstevel@tonic-gate dr_devset_t devset; 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate devset = DR_DEVS_PRESENT(hp->h_bd); 24757c478bd9Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_type != SBD_COMP_NONE) 24767c478bd9Sstevel@tonic-gate devset &= DEVSET(hp->h_sbdcmd.cmd_cm.c_id.c_type, 24777c478bd9Sstevel@tonic-gate DEVSET_ANYUNIT); 24787c478bd9Sstevel@tonic-gate 24797c478bd9Sstevel@tonic-gate /* 24807c478bd9Sstevel@tonic-gate * Handle CPUs first to deal with possible CMP 24817c478bd9Sstevel@tonic-gate * devices. If the CPU is a CMP, we need to only 24827c478bd9Sstevel@tonic-gate * increment ncm once even if there are multiple 24837c478bd9Sstevel@tonic-gate * cores for that CMP present in the devset. 24847c478bd9Sstevel@tonic-gate */ 24857c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CMP_UNITS_PER_BOARD; i++) { 24867c478bd9Sstevel@tonic-gate if (devset & DEVSET(SBD_COMP_CMP, i)) { 24877c478bd9Sstevel@tonic-gate ncm++; 24887c478bd9Sstevel@tonic-gate } 24897c478bd9Sstevel@tonic-gate } 24907c478bd9Sstevel@tonic-gate 24917c478bd9Sstevel@tonic-gate /* eliminate the CPU information from the devset */ 24927c478bd9Sstevel@tonic-gate devset &= ~(DEVSET(SBD_COMP_CMP, DEVSET_ANYUNIT)); 24937c478bd9Sstevel@tonic-gate 24947c478bd9Sstevel@tonic-gate for (i = 0; i < (sizeof (dr_devset_t) * 8); i++) { 24957c478bd9Sstevel@tonic-gate ncm += devset & 0x1; 24967c478bd9Sstevel@tonic-gate devset >>= 1; 24977c478bd9Sstevel@tonic-gate } 24987c478bd9Sstevel@tonic-gate 24997c478bd9Sstevel@tonic-gate return (ncm); 25007c478bd9Sstevel@tonic-gate } 25017c478bd9Sstevel@tonic-gate 25027c478bd9Sstevel@tonic-gate /* used by dr_mem.c */ 25037c478bd9Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 25047c478bd9Sstevel@tonic-gate dr_board_t * 25057c478bd9Sstevel@tonic-gate dr_lookup_board(int board_num) 25067c478bd9Sstevel@tonic-gate { 25077c478bd9Sstevel@tonic-gate dr_board_t *bp; 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate ASSERT(board_num >= 0 && board_num < MAX_BOARDS); 25107c478bd9Sstevel@tonic-gate 25117c478bd9Sstevel@tonic-gate bp = &dr_boardlist[board_num]; 25127c478bd9Sstevel@tonic-gate ASSERT(bp->b_num == board_num); 25137c478bd9Sstevel@tonic-gate 25147c478bd9Sstevel@tonic-gate return (bp); 25157c478bd9Sstevel@tonic-gate } 25167c478bd9Sstevel@tonic-gate 25177c478bd9Sstevel@tonic-gate static dr_dev_unit_t * 25187c478bd9Sstevel@tonic-gate dr_get_dev_unit(dr_board_t *bp, sbd_comp_type_t nt, int unit_num) 25197c478bd9Sstevel@tonic-gate { 25207c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, nt, unit_num); 25237c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_bp == bp); 25247c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_unum == unit_num); 25257c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_type == nt); 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate return (dp); 25287c478bd9Sstevel@tonic-gate } 25297c478bd9Sstevel@tonic-gate 25307c478bd9Sstevel@tonic-gate dr_cpu_unit_t * 25317c478bd9Sstevel@tonic-gate dr_get_cpu_unit(dr_board_t *bp, int unit_num) 25327c478bd9Sstevel@tonic-gate { 25337c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_CPU_UNITS_PER_BOARD); 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_CPU, unit_num); 25387c478bd9Sstevel@tonic-gate return (&dp->du_cpu); 25397c478bd9Sstevel@tonic-gate } 25407c478bd9Sstevel@tonic-gate 25417c478bd9Sstevel@tonic-gate dr_mem_unit_t * 25427c478bd9Sstevel@tonic-gate dr_get_mem_unit(dr_board_t *bp, int unit_num) 25437c478bd9Sstevel@tonic-gate { 25447c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 25457c478bd9Sstevel@tonic-gate 25467c478bd9Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_MEM_UNITS_PER_BOARD); 25477c478bd9Sstevel@tonic-gate 25487c478bd9Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_MEM, unit_num); 25497c478bd9Sstevel@tonic-gate return (&dp->du_mem); 25507c478bd9Sstevel@tonic-gate } 25517c478bd9Sstevel@tonic-gate 25527c478bd9Sstevel@tonic-gate dr_io_unit_t * 25537c478bd9Sstevel@tonic-gate dr_get_io_unit(dr_board_t *bp, int unit_num) 25547c478bd9Sstevel@tonic-gate { 25557c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 25567c478bd9Sstevel@tonic-gate 25577c478bd9Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_IO_UNITS_PER_BOARD); 25587c478bd9Sstevel@tonic-gate 25597c478bd9Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_IO, unit_num); 25607c478bd9Sstevel@tonic-gate return (&dp->du_io); 25617c478bd9Sstevel@tonic-gate } 25627c478bd9Sstevel@tonic-gate 25637c478bd9Sstevel@tonic-gate dr_common_unit_t * 25647c478bd9Sstevel@tonic-gate dr_get_common_unit(dr_board_t *bp, sbd_comp_type_t nt, int unum) 25657c478bd9Sstevel@tonic-gate { 25667c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 25677c478bd9Sstevel@tonic-gate 25687c478bd9Sstevel@tonic-gate dp = dr_get_dev_unit(bp, nt, unum); 25697c478bd9Sstevel@tonic-gate return (&dp->du_common); 25707c478bd9Sstevel@tonic-gate } 25717c478bd9Sstevel@tonic-gate 25727c478bd9Sstevel@tonic-gate static dr_devset_t 25737c478bd9Sstevel@tonic-gate dr_dev2devset(sbd_comp_id_t *cid) 25747c478bd9Sstevel@tonic-gate { 25757c478bd9Sstevel@tonic-gate static fn_t f = "dr_dev2devset"; 25767c478bd9Sstevel@tonic-gate 25777c478bd9Sstevel@tonic-gate dr_devset_t devset; 25787c478bd9Sstevel@tonic-gate int unit = cid->c_unit; 25797c478bd9Sstevel@tonic-gate 25807c478bd9Sstevel@tonic-gate switch (cid->c_type) { 25817c478bd9Sstevel@tonic-gate case SBD_COMP_NONE: 25827c478bd9Sstevel@tonic-gate devset = DEVSET(SBD_COMP_CPU, DEVSET_ANYUNIT); 25837c478bd9Sstevel@tonic-gate devset |= DEVSET(SBD_COMP_MEM, DEVSET_ANYUNIT); 25847c478bd9Sstevel@tonic-gate devset |= DEVSET(SBD_COMP_IO, DEVSET_ANYUNIT); 258525cf1a30Sjl139090 PR_ALL("%s: COMP_NONE devset = 0x%lx\n", f, devset); 25867c478bd9Sstevel@tonic-gate break; 25877c478bd9Sstevel@tonic-gate 25887c478bd9Sstevel@tonic-gate case SBD_COMP_CPU: 25897c478bd9Sstevel@tonic-gate if ((unit > MAX_CPU_UNITS_PER_BOARD) || (unit < 0)) { 25907c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 25917c478bd9Sstevel@tonic-gate "%s: invalid cpu unit# = %d", 25927c478bd9Sstevel@tonic-gate f, unit); 25937c478bd9Sstevel@tonic-gate devset = 0; 25947c478bd9Sstevel@tonic-gate } else { 25957c478bd9Sstevel@tonic-gate /* 25967c478bd9Sstevel@tonic-gate * Generate a devset that includes all the 25977c478bd9Sstevel@tonic-gate * cores of a CMP device. If this is not a 25987c478bd9Sstevel@tonic-gate * CMP, the extra cores will be eliminated 25997c478bd9Sstevel@tonic-gate * later since they are not present. This is 26007c478bd9Sstevel@tonic-gate * also true for CMP devices that do not have 26017c478bd9Sstevel@tonic-gate * all cores active. 26027c478bd9Sstevel@tonic-gate */ 26037c478bd9Sstevel@tonic-gate devset = DEVSET(SBD_COMP_CMP, unit); 26047c478bd9Sstevel@tonic-gate } 26057c478bd9Sstevel@tonic-gate 260625cf1a30Sjl139090 PR_ALL("%s: CPU devset = 0x%lx\n", f, devset); 26077c478bd9Sstevel@tonic-gate break; 26087c478bd9Sstevel@tonic-gate 26097c478bd9Sstevel@tonic-gate case SBD_COMP_MEM: 26107c478bd9Sstevel@tonic-gate if (unit == SBD_NULL_UNIT) { 26117c478bd9Sstevel@tonic-gate unit = 0; 26127c478bd9Sstevel@tonic-gate cid->c_unit = 0; 26137c478bd9Sstevel@tonic-gate } 26147c478bd9Sstevel@tonic-gate 26157c478bd9Sstevel@tonic-gate if ((unit > MAX_MEM_UNITS_PER_BOARD) || (unit < 0)) { 26167c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 26177c478bd9Sstevel@tonic-gate "%s: invalid mem unit# = %d", 26187c478bd9Sstevel@tonic-gate f, unit); 26197c478bd9Sstevel@tonic-gate devset = 0; 26207c478bd9Sstevel@tonic-gate } else 26217c478bd9Sstevel@tonic-gate devset = DEVSET(cid->c_type, unit); 26227c478bd9Sstevel@tonic-gate 262325cf1a30Sjl139090 PR_ALL("%s: MEM devset = 0x%lx\n", f, devset); 26247c478bd9Sstevel@tonic-gate break; 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate case SBD_COMP_IO: 26277c478bd9Sstevel@tonic-gate if ((unit > MAX_IO_UNITS_PER_BOARD) || (unit < 0)) { 26287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 26297c478bd9Sstevel@tonic-gate "%s: invalid io unit# = %d", 26307c478bd9Sstevel@tonic-gate f, unit); 26317c478bd9Sstevel@tonic-gate devset = 0; 26327c478bd9Sstevel@tonic-gate } else 26337c478bd9Sstevel@tonic-gate devset = DEVSET(cid->c_type, unit); 26347c478bd9Sstevel@tonic-gate 263525cf1a30Sjl139090 PR_ALL("%s: IO devset = 0x%lx\n", f, devset); 26367c478bd9Sstevel@tonic-gate break; 26377c478bd9Sstevel@tonic-gate 26387c478bd9Sstevel@tonic-gate default: 26397c478bd9Sstevel@tonic-gate case SBD_COMP_UNKNOWN: 26407c478bd9Sstevel@tonic-gate devset = 0; 26417c478bd9Sstevel@tonic-gate break; 26427c478bd9Sstevel@tonic-gate } 26437c478bd9Sstevel@tonic-gate 26447c478bd9Sstevel@tonic-gate return (devset); 26457c478bd9Sstevel@tonic-gate } 26467c478bd9Sstevel@tonic-gate 26477c478bd9Sstevel@tonic-gate /* 26487c478bd9Sstevel@tonic-gate * Converts a dynamic attachment point name to a SBD_COMP_* type. 26497c478bd9Sstevel@tonic-gate * Returns SDB_COMP_UNKNOWN if name is not recognized. 26507c478bd9Sstevel@tonic-gate */ 26517c478bd9Sstevel@tonic-gate static int 26527c478bd9Sstevel@tonic-gate dr_dev_type_to_nt(char *type) 26537c478bd9Sstevel@tonic-gate { 26547c478bd9Sstevel@tonic-gate int i; 26557c478bd9Sstevel@tonic-gate 26567c478bd9Sstevel@tonic-gate for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++) 26577c478bd9Sstevel@tonic-gate if (strcmp(dr_devattr[i].s_devtype, type) == 0) 26587c478bd9Sstevel@tonic-gate break; 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate return (dr_devattr[i].s_nodetype); 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate 26637c478bd9Sstevel@tonic-gate /* 26647c478bd9Sstevel@tonic-gate * Converts a SBD_COMP_* type to a dynamic attachment point name. 26657c478bd9Sstevel@tonic-gate * Return NULL if SBD_COMP_ type is not recognized. 26667c478bd9Sstevel@tonic-gate */ 26677c478bd9Sstevel@tonic-gate char * 26687c478bd9Sstevel@tonic-gate dr_nt_to_dev_type(int nt) 26697c478bd9Sstevel@tonic-gate { 26707c478bd9Sstevel@tonic-gate int i; 26717c478bd9Sstevel@tonic-gate 26727c478bd9Sstevel@tonic-gate for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++) 26737c478bd9Sstevel@tonic-gate if (dr_devattr[i].s_nodetype == nt) 26747c478bd9Sstevel@tonic-gate break; 26757c478bd9Sstevel@tonic-gate 26767c478bd9Sstevel@tonic-gate return (dr_devattr[i].s_devtype); 26777c478bd9Sstevel@tonic-gate } 26787c478bd9Sstevel@tonic-gate 26797c478bd9Sstevel@tonic-gate 26807c478bd9Sstevel@tonic-gate /* 26817c478bd9Sstevel@tonic-gate * State transition policy is that if there is some component for which 26827c478bd9Sstevel@tonic-gate * the state transition is valid, then let it through. The exception is 26837c478bd9Sstevel@tonic-gate * SBD_CMD_DISCONNECT. On disconnect, the state transition must be valid 26847c478bd9Sstevel@tonic-gate * for ALL components. 26857c478bd9Sstevel@tonic-gate * Returns the state that is in error, if any. 26867c478bd9Sstevel@tonic-gate */ 26877c478bd9Sstevel@tonic-gate static int 26887c478bd9Sstevel@tonic-gate dr_check_transition(dr_board_t *bp, dr_devset_t *devsetp, 26897c478bd9Sstevel@tonic-gate struct dr_state_trans *transp, int cmd) 26907c478bd9Sstevel@tonic-gate { 26917c478bd9Sstevel@tonic-gate int s, ut; 26927c478bd9Sstevel@tonic-gate int state_err = 0; 26937c478bd9Sstevel@tonic-gate dr_devset_t devset; 26947c478bd9Sstevel@tonic-gate dr_common_unit_t *cp; 26957c478bd9Sstevel@tonic-gate static fn_t f = "dr_check_transition"; 26967c478bd9Sstevel@tonic-gate 26977c478bd9Sstevel@tonic-gate devset = *devsetp; 26987c478bd9Sstevel@tonic-gate 26997c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT)) { 27007c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) { 27017c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, ut) == 0) 27027c478bd9Sstevel@tonic-gate continue; 27037c478bd9Sstevel@tonic-gate 27047c478bd9Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_CPU, ut); 27057c478bd9Sstevel@tonic-gate s = (int)cp->sbdev_state; 27067c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27077c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_CPU, ut); 27087c478bd9Sstevel@tonic-gate } else { 27097c478bd9Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27107c478bd9Sstevel@tonic-gate if (!state_err) 27117c478bd9Sstevel@tonic-gate state_err = s; 27127c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_CPU, ut); 27137c478bd9Sstevel@tonic-gate } 27147c478bd9Sstevel@tonic-gate } 27157c478bd9Sstevel@tonic-gate } 27167c478bd9Sstevel@tonic-gate } 27177c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT)) { 27187c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) { 27197c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, ut) == 0) 27207c478bd9Sstevel@tonic-gate continue; 27217c478bd9Sstevel@tonic-gate 27227c478bd9Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_MEM, ut); 27237c478bd9Sstevel@tonic-gate s = (int)cp->sbdev_state; 27247c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27257c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_MEM, ut); 27267c478bd9Sstevel@tonic-gate } else { 27277c478bd9Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27287c478bd9Sstevel@tonic-gate if (!state_err) 27297c478bd9Sstevel@tonic-gate state_err = s; 27307c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_MEM, ut); 27317c478bd9Sstevel@tonic-gate } 27327c478bd9Sstevel@tonic-gate } 27337c478bd9Sstevel@tonic-gate } 27347c478bd9Sstevel@tonic-gate } 27357c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT)) { 27367c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_IO_UNITS_PER_BOARD; ut++) { 27377c478bd9Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, ut) == 0) 27387c478bd9Sstevel@tonic-gate continue; 27397c478bd9Sstevel@tonic-gate 27407c478bd9Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_IO, ut); 27417c478bd9Sstevel@tonic-gate s = (int)cp->sbdev_state; 27427c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27437c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_IO, ut); 27447c478bd9Sstevel@tonic-gate } else { 27457c478bd9Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27467c478bd9Sstevel@tonic-gate if (!state_err) 27477c478bd9Sstevel@tonic-gate state_err = s; 27487c478bd9Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_IO, ut); 27497c478bd9Sstevel@tonic-gate } 27507c478bd9Sstevel@tonic-gate } 27517c478bd9Sstevel@tonic-gate } 27527c478bd9Sstevel@tonic-gate } 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate PR_ALL("%s: requested devset = 0x%x, final devset = 0x%x\n", 27557c478bd9Sstevel@tonic-gate f, (uint_t)*devsetp, (uint_t)devset); 27567c478bd9Sstevel@tonic-gate 27577c478bd9Sstevel@tonic-gate *devsetp = devset; 27587c478bd9Sstevel@tonic-gate /* 27597c478bd9Sstevel@tonic-gate * If there are some remaining components for which 27607c478bd9Sstevel@tonic-gate * this state transition is valid, then allow them 27617c478bd9Sstevel@tonic-gate * through, otherwise if none are left then return 27627c478bd9Sstevel@tonic-gate * the state error. The exception is SBD_CMD_DISCONNECT. 27637c478bd9Sstevel@tonic-gate * On disconnect, the state transition must be valid for ALL 27647c478bd9Sstevel@tonic-gate * components. 27657c478bd9Sstevel@tonic-gate */ 27667c478bd9Sstevel@tonic-gate if (cmd == SBD_CMD_DISCONNECT) 27677c478bd9Sstevel@tonic-gate return (state_err); 27687c478bd9Sstevel@tonic-gate return (devset ? 0 : state_err); 27697c478bd9Sstevel@tonic-gate } 27707c478bd9Sstevel@tonic-gate 27717c478bd9Sstevel@tonic-gate void 27727c478bd9Sstevel@tonic-gate dr_device_transition(dr_common_unit_t *cp, dr_state_t st) 27737c478bd9Sstevel@tonic-gate { 27747c478bd9Sstevel@tonic-gate PR_STATE("%s STATE %s(%d) -> %s(%d)\n", 27757c478bd9Sstevel@tonic-gate cp->sbdev_path, 27767c478bd9Sstevel@tonic-gate state_str[cp->sbdev_state], cp->sbdev_state, 27777c478bd9Sstevel@tonic-gate state_str[st], st); 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate cp->sbdev_state = st; 27807c478bd9Sstevel@tonic-gate if (st == DR_STATE_CONFIGURED) { 27817c478bd9Sstevel@tonic-gate cp->sbdev_ostate = SBD_STAT_CONFIGURED; 27827c478bd9Sstevel@tonic-gate if (cp->sbdev_bp->b_ostate != SBD_STAT_CONFIGURED) { 27837c478bd9Sstevel@tonic-gate cp->sbdev_bp->b_ostate = SBD_STAT_CONFIGURED; 27847c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, 27857c478bd9Sstevel@tonic-gate (void *) &cp->sbdev_bp->b_time); 27867c478bd9Sstevel@tonic-gate } 27877c478bd9Sstevel@tonic-gate } else 27887c478bd9Sstevel@tonic-gate cp->sbdev_ostate = SBD_STAT_UNCONFIGURED; 27897c478bd9Sstevel@tonic-gate 27907c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *) &cp->sbdev_time); 27917c478bd9Sstevel@tonic-gate } 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate static void 27947c478bd9Sstevel@tonic-gate dr_board_transition(dr_board_t *bp, dr_state_t st) 27957c478bd9Sstevel@tonic-gate { 27967c478bd9Sstevel@tonic-gate PR_STATE("BOARD %d STATE: %s(%d) -> %s(%d)\n", 27977c478bd9Sstevel@tonic-gate bp->b_num, 27987c478bd9Sstevel@tonic-gate state_str[bp->b_state], bp->b_state, 27997c478bd9Sstevel@tonic-gate state_str[st], st); 28007c478bd9Sstevel@tonic-gate 28017c478bd9Sstevel@tonic-gate bp->b_state = st; 28027c478bd9Sstevel@tonic-gate } 28037c478bd9Sstevel@tonic-gate 28047c478bd9Sstevel@tonic-gate void 28057c478bd9Sstevel@tonic-gate dr_op_err(int ce, dr_handle_t *hp, int code, char *fmt, ...) 28067c478bd9Sstevel@tonic-gate { 28077c478bd9Sstevel@tonic-gate sbd_error_t *err; 28087c478bd9Sstevel@tonic-gate va_list args; 28097c478bd9Sstevel@tonic-gate 28107c478bd9Sstevel@tonic-gate va_start(args, fmt); 28117c478bd9Sstevel@tonic-gate err = drerr_new_v(code, fmt, args); 28127c478bd9Sstevel@tonic-gate va_end(args); 28137c478bd9Sstevel@tonic-gate 28147c478bd9Sstevel@tonic-gate if (ce != CE_IGNORE) 28157c478bd9Sstevel@tonic-gate sbd_err_log(err, ce); 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &err); 28187c478bd9Sstevel@tonic-gate } 28197c478bd9Sstevel@tonic-gate 28207c478bd9Sstevel@tonic-gate void 28217c478bd9Sstevel@tonic-gate dr_dev_err(int ce, dr_common_unit_t *cp, int code) 28227c478bd9Sstevel@tonic-gate { 28237c478bd9Sstevel@tonic-gate sbd_error_t *err; 28247c478bd9Sstevel@tonic-gate 28257c478bd9Sstevel@tonic-gate err = drerr_new(0, code, cp->sbdev_path, NULL); 28267c478bd9Sstevel@tonic-gate 28277c478bd9Sstevel@tonic-gate if (ce != CE_IGNORE) 28287c478bd9Sstevel@tonic-gate sbd_err_log(err, ce); 28297c478bd9Sstevel@tonic-gate 28307c478bd9Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 28317c478bd9Sstevel@tonic-gate } 28327c478bd9Sstevel@tonic-gate 28337c478bd9Sstevel@tonic-gate /* 28347c478bd9Sstevel@tonic-gate * A callback routine. Called from the drmach layer as a result of 28357c478bd9Sstevel@tonic-gate * call to drmach_board_find_devices from dr_init_devlists. 28367c478bd9Sstevel@tonic-gate */ 28377c478bd9Sstevel@tonic-gate static sbd_error_t * 28387c478bd9Sstevel@tonic-gate dr_dev_found(void *data, const char *name, int unum, drmachid_t id) 28397c478bd9Sstevel@tonic-gate { 28407c478bd9Sstevel@tonic-gate dr_board_t *bp = data; 28417c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 28427c478bd9Sstevel@tonic-gate int nt; 28437c478bd9Sstevel@tonic-gate static fn_t f = "dr_dev_found"; 28447c478bd9Sstevel@tonic-gate 28457c478bd9Sstevel@tonic-gate PR_ALL("%s (board = %d, name = %s, unum = %d, id = %p)...\n", 28467c478bd9Sstevel@tonic-gate f, bp->b_num, name, unum, id); 28477c478bd9Sstevel@tonic-gate 28487c478bd9Sstevel@tonic-gate nt = dr_dev_type_to_nt((char *)name); 28497c478bd9Sstevel@tonic-gate if (nt == SBD_COMP_UNKNOWN) { 28507c478bd9Sstevel@tonic-gate /* 28517c478bd9Sstevel@tonic-gate * this should not happen. When it does, it indicates 28527c478bd9Sstevel@tonic-gate * a missmatch in devices supported by the drmach layer 28537c478bd9Sstevel@tonic-gate * vs devices supported by this layer. 28547c478bd9Sstevel@tonic-gate */ 28557c478bd9Sstevel@tonic-gate return (DR_INTERNAL_ERROR()); 28567c478bd9Sstevel@tonic-gate } 28577c478bd9Sstevel@tonic-gate 28587c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, nt, unum); 28597c478bd9Sstevel@tonic-gate 28607c478bd9Sstevel@tonic-gate /* sanity check */ 28617c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_bp == bp); 28627c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_unum == unum); 28637c478bd9Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_type == nt); 28647c478bd9Sstevel@tonic-gate 28657c478bd9Sstevel@tonic-gate /* render dynamic attachment point path of this unit */ 28667c478bd9Sstevel@tonic-gate (void) snprintf(dp->du_common.sbdev_path, 28677c478bd9Sstevel@tonic-gate sizeof (dp->du_common.sbdev_path), 28687c478bd9Sstevel@tonic-gate (nt == SBD_COMP_MEM ? "%s::%s" : "%s::%s%d"), 286925cf1a30Sjl139090 bp->b_path, name, DR_UNUM2SBD_UNUM(unum, nt)); 28707c478bd9Sstevel@tonic-gate 28717c478bd9Sstevel@tonic-gate dp->du_common.sbdev_id = id; 28727c478bd9Sstevel@tonic-gate DR_DEV_SET_PRESENT(&dp->du_common); 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate bp->b_ndev++; 28757c478bd9Sstevel@tonic-gate 28767c478bd9Sstevel@tonic-gate return (NULL); 28777c478bd9Sstevel@tonic-gate } 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate static sbd_error_t * 28807c478bd9Sstevel@tonic-gate dr_init_devlists(dr_board_t *bp) 28817c478bd9Sstevel@tonic-gate { 28827c478bd9Sstevel@tonic-gate int i; 28837c478bd9Sstevel@tonic-gate sbd_error_t *err; 28847c478bd9Sstevel@tonic-gate dr_dev_unit_t *dp; 28857c478bd9Sstevel@tonic-gate static fn_t f = "dr_init_devlists"; 28867c478bd9Sstevel@tonic-gate 28877c478bd9Sstevel@tonic-gate PR_ALL("%s (%s)...\n", f, bp->b_path); 28887c478bd9Sstevel@tonic-gate 28897c478bd9Sstevel@tonic-gate /* sanity check */ 28907c478bd9Sstevel@tonic-gate ASSERT(bp->b_ndev == 0); 28917c478bd9Sstevel@tonic-gate 28927c478bd9Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, (uint_t)-1); 28937c478bd9Sstevel@tonic-gate 28947c478bd9Sstevel@tonic-gate /* 28957c478bd9Sstevel@tonic-gate * This routine builds the board's devlist and initializes 28967c478bd9Sstevel@tonic-gate * the common portion of the unit data structures. 28977c478bd9Sstevel@tonic-gate * Note: because the common portion is considered 28987c478bd9Sstevel@tonic-gate * uninitialized, the dr_get_*_unit() routines can not 28997c478bd9Sstevel@tonic-gate * be used. 29007c478bd9Sstevel@tonic-gate */ 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate /* 29037c478bd9Sstevel@tonic-gate * Clear out old entries, if any. 29047c478bd9Sstevel@tonic-gate */ 29057c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 29067c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_CPU, i); 29077c478bd9Sstevel@tonic-gate 29087c478bd9Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29097c478bd9Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29107c478bd9Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29117c478bd9Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_CPU; 29127c478bd9Sstevel@tonic-gate } 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 29157c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_MEM, i); 29167c478bd9Sstevel@tonic-gate 29177c478bd9Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29187c478bd9Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29197c478bd9Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29207c478bd9Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_MEM; 29217c478bd9Sstevel@tonic-gate } 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 29247c478bd9Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_IO, i); 29257c478bd9Sstevel@tonic-gate 29267c478bd9Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29277c478bd9Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29287c478bd9Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29297c478bd9Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_IO; 29307c478bd9Sstevel@tonic-gate } 29317c478bd9Sstevel@tonic-gate 29327c478bd9Sstevel@tonic-gate err = NULL; 29337c478bd9Sstevel@tonic-gate if (bp->b_id) { 29347c478bd9Sstevel@tonic-gate /* find devices on this board */ 29357c478bd9Sstevel@tonic-gate err = drmach_board_find_devices( 29367c478bd9Sstevel@tonic-gate bp->b_id, bp, dr_dev_found); 29377c478bd9Sstevel@tonic-gate } 29387c478bd9Sstevel@tonic-gate 29397c478bd9Sstevel@tonic-gate return (err); 29407c478bd9Sstevel@tonic-gate } 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate /* 29437c478bd9Sstevel@tonic-gate * Return the unit number of the respective drmachid if 29447c478bd9Sstevel@tonic-gate * it's found to be attached. 29457c478bd9Sstevel@tonic-gate */ 29467c478bd9Sstevel@tonic-gate static int 29477c478bd9Sstevel@tonic-gate dr_check_unit_attached(dr_common_unit_t *cp) 29487c478bd9Sstevel@tonic-gate { 29497c478bd9Sstevel@tonic-gate int rv = 0; 29507c478bd9Sstevel@tonic-gate processorid_t cpuid; 29517c478bd9Sstevel@tonic-gate uint64_t basepa, endpa; 29527c478bd9Sstevel@tonic-gate struct memlist *ml; 29537c478bd9Sstevel@tonic-gate extern struct memlist *phys_install; 29547c478bd9Sstevel@tonic-gate sbd_error_t *err; 29557c478bd9Sstevel@tonic-gate int yes; 29567c478bd9Sstevel@tonic-gate static fn_t f = "dr_check_unit_attached"; 29577c478bd9Sstevel@tonic-gate 29587c478bd9Sstevel@tonic-gate switch (cp->sbdev_type) { 29597c478bd9Sstevel@tonic-gate case SBD_COMP_CPU: 29607c478bd9Sstevel@tonic-gate err = drmach_cpu_get_id(cp->sbdev_id, &cpuid); 29617c478bd9Sstevel@tonic-gate if (err) { 29627c478bd9Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29637c478bd9Sstevel@tonic-gate rv = -1; 29647c478bd9Sstevel@tonic-gate break; 29657c478bd9Sstevel@tonic-gate } 29667c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 29677c478bd9Sstevel@tonic-gate if (cpu_get(cpuid) == NULL) 29687c478bd9Sstevel@tonic-gate rv = -1; 29697c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 29707c478bd9Sstevel@tonic-gate break; 29717c478bd9Sstevel@tonic-gate 29727c478bd9Sstevel@tonic-gate case SBD_COMP_MEM: 29737c478bd9Sstevel@tonic-gate err = drmach_mem_get_base_physaddr(cp->sbdev_id, &basepa); 29747c478bd9Sstevel@tonic-gate if (err) { 29757c478bd9Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29767c478bd9Sstevel@tonic-gate rv = -1; 29777c478bd9Sstevel@tonic-gate break; 29787c478bd9Sstevel@tonic-gate } 29797c478bd9Sstevel@tonic-gate 29807c478bd9Sstevel@tonic-gate /* 29817c478bd9Sstevel@tonic-gate * basepa may not be on a alignment boundary, make it so. 29827c478bd9Sstevel@tonic-gate */ 29837c478bd9Sstevel@tonic-gate err = drmach_mem_get_slice_size(cp->sbdev_id, &endpa); 29847c478bd9Sstevel@tonic-gate if (err) { 29857c478bd9Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29867c478bd9Sstevel@tonic-gate rv = -1; 29877c478bd9Sstevel@tonic-gate break; 29887c478bd9Sstevel@tonic-gate } 29897c478bd9Sstevel@tonic-gate 29907c478bd9Sstevel@tonic-gate basepa &= ~(endpa - 1); 29917c478bd9Sstevel@tonic-gate endpa += basepa; 29927c478bd9Sstevel@tonic-gate 29937c478bd9Sstevel@tonic-gate /* 29947c478bd9Sstevel@tonic-gate * Check if base address is in phys_install. 29957c478bd9Sstevel@tonic-gate */ 29967c478bd9Sstevel@tonic-gate memlist_read_lock(); 299756f33205SJonathan Adams for (ml = phys_install; ml; ml = ml->ml_next) 299856f33205SJonathan Adams if ((endpa <= ml->ml_address) || 299956f33205SJonathan Adams (basepa >= (ml->ml_address + ml->ml_size))) 30007c478bd9Sstevel@tonic-gate continue; 30017c478bd9Sstevel@tonic-gate else 30027c478bd9Sstevel@tonic-gate break; 30037c478bd9Sstevel@tonic-gate memlist_read_unlock(); 30047c478bd9Sstevel@tonic-gate if (ml == NULL) 30057c478bd9Sstevel@tonic-gate rv = -1; 30067c478bd9Sstevel@tonic-gate break; 30077c478bd9Sstevel@tonic-gate 30087c478bd9Sstevel@tonic-gate case SBD_COMP_IO: 30097c478bd9Sstevel@tonic-gate err = drmach_io_is_attached(cp->sbdev_id, &yes); 30107c478bd9Sstevel@tonic-gate if (err) { 30117c478bd9Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 30127c478bd9Sstevel@tonic-gate rv = -1; 30137c478bd9Sstevel@tonic-gate break; 30147c478bd9Sstevel@tonic-gate } else if (!yes) 30157c478bd9Sstevel@tonic-gate rv = -1; 30167c478bd9Sstevel@tonic-gate break; 30177c478bd9Sstevel@tonic-gate 30187c478bd9Sstevel@tonic-gate default: 301904580fdfSmathue PR_ALL("%s: unexpected nodetype(%d) for id 0x%p\n", 30207c478bd9Sstevel@tonic-gate f, cp->sbdev_type, cp->sbdev_id); 30217c478bd9Sstevel@tonic-gate rv = -1; 30227c478bd9Sstevel@tonic-gate break; 30237c478bd9Sstevel@tonic-gate } 30247c478bd9Sstevel@tonic-gate 30257c478bd9Sstevel@tonic-gate return (rv); 30267c478bd9Sstevel@tonic-gate } 30277c478bd9Sstevel@tonic-gate 30287c478bd9Sstevel@tonic-gate /* 30297c478bd9Sstevel@tonic-gate * See if drmach recognizes the passthru command. DRMACH expects the 30307c478bd9Sstevel@tonic-gate * id to identify the thing to which the command is being applied. Using 30317c478bd9Sstevel@tonic-gate * nonsense SBD terms, that information has been perversely encoded in the 30327c478bd9Sstevel@tonic-gate * c_id member of the sbd_cmd_t structure. This logic reads those tea 30337c478bd9Sstevel@tonic-gate * leaves, finds the associated drmach id, then calls drmach to process 30347c478bd9Sstevel@tonic-gate * the passthru command. 30357c478bd9Sstevel@tonic-gate */ 30367c478bd9Sstevel@tonic-gate static int 30377c478bd9Sstevel@tonic-gate dr_pt_try_drmach(dr_handle_t *hp) 30387c478bd9Sstevel@tonic-gate { 30397c478bd9Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 30407c478bd9Sstevel@tonic-gate sbd_comp_id_t *comp_id = &hp->h_sbdcmd.cmd_cm.c_id; 30417c478bd9Sstevel@tonic-gate drmachid_t id; 30427c478bd9Sstevel@tonic-gate 30437c478bd9Sstevel@tonic-gate if (comp_id->c_type == SBD_COMP_NONE) { 30447c478bd9Sstevel@tonic-gate id = bp->b_id; 30457c478bd9Sstevel@tonic-gate } else { 30467c478bd9Sstevel@tonic-gate sbd_comp_type_t nt; 30477c478bd9Sstevel@tonic-gate 30487c478bd9Sstevel@tonic-gate nt = dr_dev_type_to_nt(comp_id->c_name); 30497c478bd9Sstevel@tonic-gate if (nt == SBD_COMP_UNKNOWN) { 30507c478bd9Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_INVAL, comp_id->c_name); 30517c478bd9Sstevel@tonic-gate id = 0; 30527c478bd9Sstevel@tonic-gate } else { 30537c478bd9Sstevel@tonic-gate /* pt command applied to dynamic attachment point */ 30547c478bd9Sstevel@tonic-gate dr_common_unit_t *cp; 30557c478bd9Sstevel@tonic-gate cp = dr_get_common_unit(bp, nt, comp_id->c_unit); 30567c478bd9Sstevel@tonic-gate id = cp->sbdev_id; 30577c478bd9Sstevel@tonic-gate } 30587c478bd9Sstevel@tonic-gate } 30597c478bd9Sstevel@tonic-gate 30607c478bd9Sstevel@tonic-gate if (hp->h_err == NULL) 30617c478bd9Sstevel@tonic-gate hp->h_err = drmach_passthru(id, &hp->h_opts); 30627c478bd9Sstevel@tonic-gate 30637c478bd9Sstevel@tonic-gate return (hp->h_err == NULL ? 0 : -1); 30647c478bd9Sstevel@tonic-gate } 30657c478bd9Sstevel@tonic-gate 30667c478bd9Sstevel@tonic-gate static int 30677c478bd9Sstevel@tonic-gate dr_pt_ioctl(dr_handle_t *hp) 30687c478bd9Sstevel@tonic-gate { 30697c478bd9Sstevel@tonic-gate int cmd, rv, len; 30707c478bd9Sstevel@tonic-gate int32_t sz; 30717c478bd9Sstevel@tonic-gate int found; 30727c478bd9Sstevel@tonic-gate char *copts; 30737c478bd9Sstevel@tonic-gate static fn_t f = "dr_pt_ioctl"; 30747c478bd9Sstevel@tonic-gate 30757c478bd9Sstevel@tonic-gate PR_ALL("%s...\n", f); 30767c478bd9Sstevel@tonic-gate 30777c478bd9Sstevel@tonic-gate sz = hp->h_opts.size; 30787c478bd9Sstevel@tonic-gate copts = hp->h_opts.copts; 30797c478bd9Sstevel@tonic-gate 30807c478bd9Sstevel@tonic-gate if (sz == 0 || copts == (char *)NULL) { 30817c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s: invalid passthru args", f); 30827c478bd9Sstevel@tonic-gate return (EINVAL); 30837c478bd9Sstevel@tonic-gate } 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate found = 0; 30867c478bd9Sstevel@tonic-gate for (cmd = 0; cmd < (sizeof (pt_arr) / sizeof (pt_arr[0])); cmd++) { 30877c478bd9Sstevel@tonic-gate len = strlen(pt_arr[cmd].pt_name); 30887c478bd9Sstevel@tonic-gate found = (strncmp(pt_arr[cmd].pt_name, copts, len) == 0); 30897c478bd9Sstevel@tonic-gate if (found) 30907c478bd9Sstevel@tonic-gate break; 30917c478bd9Sstevel@tonic-gate } 30927c478bd9Sstevel@tonic-gate 30937c478bd9Sstevel@tonic-gate if (found) 30947c478bd9Sstevel@tonic-gate rv = (*pt_arr[cmd].pt_func)(hp); 30957c478bd9Sstevel@tonic-gate else 30967c478bd9Sstevel@tonic-gate rv = dr_pt_try_drmach(hp); 30977c478bd9Sstevel@tonic-gate 30987c478bd9Sstevel@tonic-gate return (rv); 30997c478bd9Sstevel@tonic-gate } 31007c478bd9Sstevel@tonic-gate 31017c478bd9Sstevel@tonic-gate /* 31027c478bd9Sstevel@tonic-gate * Called at driver load time to determine the state and condition 31037c478bd9Sstevel@tonic-gate * of an existing board in the system. 31047c478bd9Sstevel@tonic-gate */ 31057c478bd9Sstevel@tonic-gate static void 31067c478bd9Sstevel@tonic-gate dr_board_discovery(dr_board_t *bp) 31077c478bd9Sstevel@tonic-gate { 31087c478bd9Sstevel@tonic-gate int i; 31097c478bd9Sstevel@tonic-gate dr_devset_t devs_lost, devs_attached = 0; 31107c478bd9Sstevel@tonic-gate dr_cpu_unit_t *cp; 31117c478bd9Sstevel@tonic-gate dr_mem_unit_t *mp; 31127c478bd9Sstevel@tonic-gate dr_io_unit_t *ip; 31137c478bd9Sstevel@tonic-gate static fn_t f = "dr_board_discovery"; 31147c478bd9Sstevel@tonic-gate 31157c478bd9Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp) == 0) { 31167c478bd9Sstevel@tonic-gate PR_ALL("%s: board %d has no devices present\n", 31177c478bd9Sstevel@tonic-gate f, bp->b_num); 31187c478bd9Sstevel@tonic-gate return; 31197c478bd9Sstevel@tonic-gate } 31207c478bd9Sstevel@tonic-gate 31217c478bd9Sstevel@tonic-gate /* 31227c478bd9Sstevel@tonic-gate * Check for existence of cpus. 31237c478bd9Sstevel@tonic-gate */ 31247c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 31257c478bd9Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&cp->sbc_cm)) 31287c478bd9Sstevel@tonic-gate continue; 31297c478bd9Sstevel@tonic-gate 31307c478bd9Sstevel@tonic-gate if (dr_check_unit_attached(&cp->sbc_cm) >= 0) { 31317c478bd9Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&cp->sbc_cm); 31327c478bd9Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_CPU, i); 31337c478bd9Sstevel@tonic-gate PR_ALL("%s: board %d, cpu-unit %d - attached\n", 31347c478bd9Sstevel@tonic-gate f, bp->b_num, i); 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate dr_init_cpu_unit(cp); 31377c478bd9Sstevel@tonic-gate } 31387c478bd9Sstevel@tonic-gate 31397c478bd9Sstevel@tonic-gate /* 31407c478bd9Sstevel@tonic-gate * Check for existence of memory. 31417c478bd9Sstevel@tonic-gate */ 31427c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 31437c478bd9Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 31447c478bd9Sstevel@tonic-gate 31457c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&mp->sbm_cm)) 31467c478bd9Sstevel@tonic-gate continue; 31477c478bd9Sstevel@tonic-gate 31487c478bd9Sstevel@tonic-gate if (dr_check_unit_attached(&mp->sbm_cm) >= 0) { 31497c478bd9Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&mp->sbm_cm); 31507c478bd9Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_MEM, i); 31517c478bd9Sstevel@tonic-gate PR_ALL("%s: board %d, mem-unit %d - attached\n", 31527c478bd9Sstevel@tonic-gate f, bp->b_num, i); 31537c478bd9Sstevel@tonic-gate } 31547c478bd9Sstevel@tonic-gate dr_init_mem_unit(mp); 31557c478bd9Sstevel@tonic-gate } 31567c478bd9Sstevel@tonic-gate 31577c478bd9Sstevel@tonic-gate /* 31587c478bd9Sstevel@tonic-gate * Check for i/o state. 31597c478bd9Sstevel@tonic-gate */ 31607c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 31617c478bd9Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 31627c478bd9Sstevel@tonic-gate 31637c478bd9Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&ip->sbi_cm)) 31647c478bd9Sstevel@tonic-gate continue; 31657c478bd9Sstevel@tonic-gate 31667c478bd9Sstevel@tonic-gate if (dr_check_unit_attached(&ip->sbi_cm) >= 0) { 31677c478bd9Sstevel@tonic-gate /* 31687c478bd9Sstevel@tonic-gate * Found it! 31697c478bd9Sstevel@tonic-gate */ 31707c478bd9Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&ip->sbi_cm); 31717c478bd9Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_IO, i); 31727c478bd9Sstevel@tonic-gate PR_ALL("%s: board %d, io-unit %d - attached\n", 31737c478bd9Sstevel@tonic-gate f, bp->b_num, i); 31747c478bd9Sstevel@tonic-gate } 31757c478bd9Sstevel@tonic-gate dr_init_io_unit(ip); 31767c478bd9Sstevel@tonic-gate } 31777c478bd9Sstevel@tonic-gate 31787c478bd9Sstevel@tonic-gate DR_DEVS_CONFIGURE(bp, devs_attached); 31797c478bd9Sstevel@tonic-gate if (devs_attached && ((devs_lost = DR_DEVS_UNATTACHED(bp)) != 0)) { 31807c478bd9Sstevel@tonic-gate int ut; 31817c478bd9Sstevel@tonic-gate /* 31827c478bd9Sstevel@tonic-gate * It is not legal on board discovery to have a 31837c478bd9Sstevel@tonic-gate * board that is only partially attached. A board 31847c478bd9Sstevel@tonic-gate * is either all attached or all connected. If a 31857c478bd9Sstevel@tonic-gate * board has at least one attached device, then 31867c478bd9Sstevel@tonic-gate * the the remaining devices, if any, must have 31877c478bd9Sstevel@tonic-gate * been lost or disconnected. These devices can 31887c478bd9Sstevel@tonic-gate * only be recovered by a full attach from scratch. 31897c478bd9Sstevel@tonic-gate * Note that devices previously in the unreferenced 31907c478bd9Sstevel@tonic-gate * state are subsequently lost until the next full 31917c478bd9Sstevel@tonic-gate * attach. This is necessary since the driver unload 31927c478bd9Sstevel@tonic-gate * that must have occurred would have wiped out the 31937c478bd9Sstevel@tonic-gate * information necessary to re-configure the device 31947c478bd9Sstevel@tonic-gate * back online, e.g. memlist. 31957c478bd9Sstevel@tonic-gate */ 319625cf1a30Sjl139090 PR_ALL("%s: some devices LOST (0x%lx)...\n", f, devs_lost); 31977c478bd9Sstevel@tonic-gate 31987c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) { 31997c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_CPU, ut)) 32007c478bd9Sstevel@tonic-gate continue; 32017c478bd9Sstevel@tonic-gate 32027c478bd9Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, ut); 32037c478bd9Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY); 32047c478bd9Sstevel@tonic-gate } 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) { 32077c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_MEM, ut)) 32087c478bd9Sstevel@tonic-gate continue; 32097c478bd9Sstevel@tonic-gate 32107c478bd9Sstevel@tonic-gate mp = dr_get_mem_unit(bp, ut); 32117c478bd9Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY); 32127c478bd9Sstevel@tonic-gate } 32137c478bd9Sstevel@tonic-gate 32147c478bd9Sstevel@tonic-gate for (ut = 0; ut < MAX_IO_UNITS_PER_BOARD; ut++) { 32157c478bd9Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_IO, ut)) 32167c478bd9Sstevel@tonic-gate continue; 32177c478bd9Sstevel@tonic-gate 32187c478bd9Sstevel@tonic-gate ip = dr_get_io_unit(bp, ut); 32197c478bd9Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY); 32207c478bd9Sstevel@tonic-gate } 32217c478bd9Sstevel@tonic-gate 32227c478bd9Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, devs_lost); 32237c478bd9Sstevel@tonic-gate } 32247c478bd9Sstevel@tonic-gate } 32257c478bd9Sstevel@tonic-gate 32267c478bd9Sstevel@tonic-gate static int 32277c478bd9Sstevel@tonic-gate dr_board_init(dr_board_t *bp, dev_info_t *dip, int bd) 32287c478bd9Sstevel@tonic-gate { 32297c478bd9Sstevel@tonic-gate sbd_error_t *err; 32307c478bd9Sstevel@tonic-gate 32317c478bd9Sstevel@tonic-gate mutex_init(&bp->b_lock, NULL, MUTEX_DRIVER, NULL); 32327c478bd9Sstevel@tonic-gate mutex_init(&bp->b_slock, NULL, MUTEX_DRIVER, NULL); 32337c478bd9Sstevel@tonic-gate cv_init(&bp->b_scv, NULL, CV_DRIVER, NULL); 32347c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 32357c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 32367c478bd9Sstevel@tonic-gate bp->b_cond = SBD_COND_UNKNOWN; 32377c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32387c478bd9Sstevel@tonic-gate 32397c478bd9Sstevel@tonic-gate (void) drmach_board_lookup(bd, &bp->b_id); 32407c478bd9Sstevel@tonic-gate bp->b_num = bd; 32417c478bd9Sstevel@tonic-gate bp->b_dip = dip; 32427c478bd9Sstevel@tonic-gate 32437c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_CPU)] = GETSTRUCT(dr_dev_unit_t, 32447c478bd9Sstevel@tonic-gate MAX_CPU_UNITS_PER_BOARD); 32457c478bd9Sstevel@tonic-gate 32467c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_MEM)] = GETSTRUCT(dr_dev_unit_t, 32477c478bd9Sstevel@tonic-gate MAX_MEM_UNITS_PER_BOARD); 32487c478bd9Sstevel@tonic-gate 32497c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_IO)] = GETSTRUCT(dr_dev_unit_t, 32507c478bd9Sstevel@tonic-gate MAX_IO_UNITS_PER_BOARD); 32517c478bd9Sstevel@tonic-gate 32527c478bd9Sstevel@tonic-gate /* 32537c478bd9Sstevel@tonic-gate * Initialize the devlists 32547c478bd9Sstevel@tonic-gate */ 32557c478bd9Sstevel@tonic-gate err = dr_init_devlists(bp); 32567c478bd9Sstevel@tonic-gate if (err) { 32577c478bd9Sstevel@tonic-gate sbd_err_clear(&err); 32587c478bd9Sstevel@tonic-gate dr_board_destroy(bp); 32597c478bd9Sstevel@tonic-gate return (-1); 32607c478bd9Sstevel@tonic-gate } else if (bp->b_ndev == 0) { 32617c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 32627c478bd9Sstevel@tonic-gate } else { 32637c478bd9Sstevel@tonic-gate /* 32647c478bd9Sstevel@tonic-gate * Couldn't have made it down here without 32657c478bd9Sstevel@tonic-gate * having found at least one device. 32667c478bd9Sstevel@tonic-gate */ 32677c478bd9Sstevel@tonic-gate ASSERT(DR_DEVS_PRESENT(bp) != 0); 32687c478bd9Sstevel@tonic-gate /* 32697c478bd9Sstevel@tonic-gate * Check the state of any possible devices on the 32707c478bd9Sstevel@tonic-gate * board. 32717c478bd9Sstevel@tonic-gate */ 32727c478bd9Sstevel@tonic-gate dr_board_discovery(bp); 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate bp->b_assigned = 1; 32757c478bd9Sstevel@tonic-gate 32767c478bd9Sstevel@tonic-gate if (DR_DEVS_UNATTACHED(bp) == 0) { 32777c478bd9Sstevel@tonic-gate /* 32787c478bd9Sstevel@tonic-gate * The board has no unattached devices, therefore 32797c478bd9Sstevel@tonic-gate * by reason of insanity it must be configured! 32807c478bd9Sstevel@tonic-gate */ 32817c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 32827c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_CONFIGURED; 32837c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32847c478bd9Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 32857c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32867c478bd9Sstevel@tonic-gate } else if (DR_DEVS_ATTACHED(bp)) { 32877c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 32887c478bd9Sstevel@tonic-gate bp->b_ostate = SBD_STAT_CONFIGURED; 32897c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32907c478bd9Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 32917c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32927c478bd9Sstevel@tonic-gate } else { 32937c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONNECTED); 32947c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32957c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32967c478bd9Sstevel@tonic-gate } 32977c478bd9Sstevel@tonic-gate } 32987c478bd9Sstevel@tonic-gate 32997c478bd9Sstevel@tonic-gate return (0); 33007c478bd9Sstevel@tonic-gate } 33017c478bd9Sstevel@tonic-gate 33027c478bd9Sstevel@tonic-gate static void 33037c478bd9Sstevel@tonic-gate dr_board_destroy(dr_board_t *bp) 33047c478bd9Sstevel@tonic-gate { 33057c478bd9Sstevel@tonic-gate PR_ALL("dr_board_destroy: num %d, path %s\n", 33067c478bd9Sstevel@tonic-gate bp->b_num, bp->b_path); 33077c478bd9Sstevel@tonic-gate 33087c478bd9Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 33097c478bd9Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 33107c478bd9Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 33117c478bd9Sstevel@tonic-gate 33127c478bd9Sstevel@tonic-gate /* 33137c478bd9Sstevel@tonic-gate * Free up MEM unit structs. 33147c478bd9Sstevel@tonic-gate */ 33157c478bd9Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_MEM)], 33167c478bd9Sstevel@tonic-gate dr_dev_unit_t, MAX_MEM_UNITS_PER_BOARD); 33177c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_MEM)] = NULL; 33187c478bd9Sstevel@tonic-gate /* 33197c478bd9Sstevel@tonic-gate * Free up CPU unit structs. 33207c478bd9Sstevel@tonic-gate */ 33217c478bd9Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_CPU)], 33227c478bd9Sstevel@tonic-gate dr_dev_unit_t, MAX_CPU_UNITS_PER_BOARD); 33237c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_CPU)] = NULL; 33247c478bd9Sstevel@tonic-gate /* 33257c478bd9Sstevel@tonic-gate * Free up IO unit structs. 33267c478bd9Sstevel@tonic-gate */ 33277c478bd9Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_IO)], 33287c478bd9Sstevel@tonic-gate dr_dev_unit_t, MAX_IO_UNITS_PER_BOARD); 33297c478bd9Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_IO)] = NULL; 33307c478bd9Sstevel@tonic-gate 33317c478bd9Sstevel@tonic-gate mutex_destroy(&bp->b_lock); 33327c478bd9Sstevel@tonic-gate mutex_destroy(&bp->b_slock); 33337c478bd9Sstevel@tonic-gate cv_destroy(&bp->b_scv); 33347c478bd9Sstevel@tonic-gate } 33357c478bd9Sstevel@tonic-gate 33367c478bd9Sstevel@tonic-gate void 33377c478bd9Sstevel@tonic-gate dr_lock_status(dr_board_t *bp) 33387c478bd9Sstevel@tonic-gate { 33397c478bd9Sstevel@tonic-gate mutex_enter(&bp->b_slock); 33407c478bd9Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) 33417c478bd9Sstevel@tonic-gate cv_wait(&bp->b_scv, &bp->b_slock); 33427c478bd9Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 33437c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 33447c478bd9Sstevel@tonic-gate } 33457c478bd9Sstevel@tonic-gate 33467c478bd9Sstevel@tonic-gate void 33477c478bd9Sstevel@tonic-gate dr_unlock_status(dr_board_t *bp) 33487c478bd9Sstevel@tonic-gate { 33497c478bd9Sstevel@tonic-gate mutex_enter(&bp->b_slock); 33507c478bd9Sstevel@tonic-gate bp->b_sflags &= ~DR_BSLOCK; 33517c478bd9Sstevel@tonic-gate cv_signal(&bp->b_scv); 33527c478bd9Sstevel@tonic-gate mutex_exit(&bp->b_slock); 33537c478bd9Sstevel@tonic-gate } 33547c478bd9Sstevel@tonic-gate 33557c478bd9Sstevel@tonic-gate /* 33567c478bd9Sstevel@tonic-gate * Extract flags passed via ioctl. 33577c478bd9Sstevel@tonic-gate */ 33587c478bd9Sstevel@tonic-gate int 33597c478bd9Sstevel@tonic-gate dr_cmd_flags(dr_handle_t *hp) 33607c478bd9Sstevel@tonic-gate { 33617c478bd9Sstevel@tonic-gate return (hp->h_sbdcmd.cmd_cm.c_flags); 33627c478bd9Sstevel@tonic-gate } 3363