10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1772Sjl139090 * Common Development and Distribution License (the "License"). 6*1772Sjl139090 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1772Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * PIM-DR layer of DR driver. Provides interface between user 300Sstevel@tonic-gate * level applications and the PSM-DR layer. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/note.h> 340Sstevel@tonic-gate #include <sys/debug.h> 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/errno.h> 370Sstevel@tonic-gate #include <sys/cred.h> 380Sstevel@tonic-gate #include <sys/dditypes.h> 390Sstevel@tonic-gate #include <sys/devops.h> 400Sstevel@tonic-gate #include <sys/modctl.h> 410Sstevel@tonic-gate #include <sys/poll.h> 420Sstevel@tonic-gate #include <sys/conf.h> 430Sstevel@tonic-gate #include <sys/ddi.h> 440Sstevel@tonic-gate #include <sys/sunddi.h> 450Sstevel@tonic-gate #include <sys/sunndi.h> 460Sstevel@tonic-gate #include <sys/stat.h> 470Sstevel@tonic-gate #include <sys/kmem.h> 480Sstevel@tonic-gate #include <sys/processor.h> 490Sstevel@tonic-gate #include <sys/cpuvar.h> 500Sstevel@tonic-gate #include <sys/mem_config.h> 510Sstevel@tonic-gate 520Sstevel@tonic-gate #include <sys/autoconf.h> 530Sstevel@tonic-gate #include <sys/cmn_err.h> 540Sstevel@tonic-gate 550Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 560Sstevel@tonic-gate #include <sys/promif.h> 570Sstevel@tonic-gate #include <sys/machsystm.h> 580Sstevel@tonic-gate 590Sstevel@tonic-gate #include <sys/dr.h> 600Sstevel@tonic-gate #include <sys/drmach.h> 610Sstevel@tonic-gate #include <sys/dr_util.h> 620Sstevel@tonic-gate 630Sstevel@tonic-gate extern int nulldev(); 640Sstevel@tonic-gate extern int nodev(); 650Sstevel@tonic-gate extern struct memlist *phys_install; 660Sstevel@tonic-gate 670Sstevel@tonic-gate #ifdef DEBUG 680Sstevel@tonic-gate uint_t dr_debug = 0; /* dr.h for bit values */ 690Sstevel@tonic-gate #endif /* DEBUG */ 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * NOTE: state_str, nt_str and SBD_CMD_STR are only used in a debug 730Sstevel@tonic-gate * kernel. They are, however, referenced during both debug and non-debug 740Sstevel@tonic-gate * compiles. 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate 770Sstevel@tonic-gate static char *state_str[] = { 780Sstevel@tonic-gate "EMPTY", "OCCUPIED", "CONNECTED", "UNCONFIGURED", 790Sstevel@tonic-gate "PARTIAL", "CONFIGURED", "RELEASE", "UNREFERENCED", 800Sstevel@tonic-gate "FATAL" 810Sstevel@tonic-gate }; 820Sstevel@tonic-gate 830Sstevel@tonic-gate #define SBD_CMD_STR(c) \ 840Sstevel@tonic-gate (((c) == SBD_CMD_ASSIGN) ? "ASSIGN" : \ 850Sstevel@tonic-gate ((c) == SBD_CMD_UNASSIGN) ? "UNASSIGN" : \ 860Sstevel@tonic-gate ((c) == SBD_CMD_POWERON) ? "POWERON" : \ 870Sstevel@tonic-gate ((c) == SBD_CMD_POWEROFF) ? "POWEROFF" : \ 880Sstevel@tonic-gate ((c) == SBD_CMD_TEST) ? "TEST" : \ 890Sstevel@tonic-gate ((c) == SBD_CMD_CONNECT) ? "CONNECT" : \ 900Sstevel@tonic-gate ((c) == SBD_CMD_DISCONNECT) ? "DISCONNECT" : \ 910Sstevel@tonic-gate ((c) == SBD_CMD_CONFIGURE) ? "CONFIGURE" : \ 920Sstevel@tonic-gate ((c) == SBD_CMD_UNCONFIGURE) ? "UNCONFIGURE" : \ 930Sstevel@tonic-gate ((c) == SBD_CMD_GETNCM) ? "GETNCM" : \ 940Sstevel@tonic-gate ((c) == SBD_CMD_PASSTHRU) ? "PASSTHRU" : \ 950Sstevel@tonic-gate ((c) == SBD_CMD_STATUS) ? "STATUS" : "unknown") 960Sstevel@tonic-gate 970Sstevel@tonic-gate #define DR_GET_BOARD_DEVUNIT(sb, ut, un) (&((sb)->b_dev[NIX(ut)][un])) 980Sstevel@tonic-gate 990Sstevel@tonic-gate #define DR_MAKE_MINOR(i, b) (((i) << 16) | (b)) 1000Sstevel@tonic-gate #define DR_MINOR2INST(m) (((m) >> 16) & 0xffff) 1010Sstevel@tonic-gate #define DR_MINOR2BNUM(m) ((m) & 0xffff) 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* for the DR*INTERNAL_ERROR macros. see sys/dr.h. */ 1040Sstevel@tonic-gate static char *dr_ie_fmt = "dr.c %d"; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* struct for drmach device name to sbd_comp_type_t mapping */ 1070Sstevel@tonic-gate typedef struct { 1080Sstevel@tonic-gate char *s_devtype; 1090Sstevel@tonic-gate sbd_comp_type_t s_nodetype; 1100Sstevel@tonic-gate } dr_devname_t; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* struct to map starfire device attributes - name:sbd_comp_type_t */ 1130Sstevel@tonic-gate static dr_devname_t dr_devattr[] = { 1140Sstevel@tonic-gate { DRMACH_DEVTYPE_MEM, SBD_COMP_MEM }, 1150Sstevel@tonic-gate { DRMACH_DEVTYPE_CPU, SBD_COMP_CPU }, 1160Sstevel@tonic-gate { DRMACH_DEVTYPE_PCI, SBD_COMP_IO }, 117*1772Sjl139090 #if defined(DRMACH_DEVTYPE_SBUS) 1180Sstevel@tonic-gate { DRMACH_DEVTYPE_SBUS, SBD_COMP_IO }, 119*1772Sjl139090 #endif 1200Sstevel@tonic-gate #if defined(DRMACH_DEVTYPE_WCI) 1210Sstevel@tonic-gate { DRMACH_DEVTYPE_WCI, SBD_COMP_IO }, 1220Sstevel@tonic-gate #endif 1230Sstevel@tonic-gate /* last s_devtype must be NULL, s_nodetype must be SBD_COMP_UNKNOWN */ 1240Sstevel@tonic-gate { NULL, SBD_COMP_UNKNOWN } 1250Sstevel@tonic-gate }; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1280Sstevel@tonic-gate * Per instance soft-state structure. 1290Sstevel@tonic-gate */ 1300Sstevel@tonic-gate typedef struct dr_softstate { 1310Sstevel@tonic-gate dev_info_t *dip; 1320Sstevel@tonic-gate dr_board_t *boards; 1330Sstevel@tonic-gate kmutex_t i_lock; 1340Sstevel@tonic-gate int dr_initialized; 1350Sstevel@tonic-gate } dr_softstate_t; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* 1380Sstevel@tonic-gate * dr Global data elements 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate struct dr_global { 1410Sstevel@tonic-gate dr_softstate_t *softsp; /* pointer to initialize soft state */ 1420Sstevel@tonic-gate kmutex_t lock; 1430Sstevel@tonic-gate } dr_g; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate dr_unsafe_devs_t dr_unsafe_devs; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Table of known passthru commands. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate struct { 1520Sstevel@tonic-gate char *pt_name; 1530Sstevel@tonic-gate int (*pt_func)(dr_handle_t *); 1540Sstevel@tonic-gate } pt_arr[] = { 1550Sstevel@tonic-gate "quiesce", dr_pt_test_suspend, 1560Sstevel@tonic-gate }; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate int dr_modunload_okay = 0; /* set to non-zero to allow unload */ 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * State transition table. States valid transitions for "board" state. 1620Sstevel@tonic-gate * Recall that non-zero return value terminates operation, however 1630Sstevel@tonic-gate * the herrno value is what really indicates an error , if any. 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate static int 1660Sstevel@tonic-gate _cmd2index(int c) 1670Sstevel@tonic-gate { 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * Translate DR CMD to index into dr_state_transition. 1700Sstevel@tonic-gate */ 1710Sstevel@tonic-gate switch (c) { 1720Sstevel@tonic-gate case SBD_CMD_CONNECT: return (0); 1730Sstevel@tonic-gate case SBD_CMD_DISCONNECT: return (1); 1740Sstevel@tonic-gate case SBD_CMD_CONFIGURE: return (2); 1750Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: return (3); 1760Sstevel@tonic-gate case SBD_CMD_ASSIGN: return (4); 1770Sstevel@tonic-gate case SBD_CMD_UNASSIGN: return (5); 1780Sstevel@tonic-gate case SBD_CMD_POWERON: return (6); 1790Sstevel@tonic-gate case SBD_CMD_POWEROFF: return (7); 1800Sstevel@tonic-gate case SBD_CMD_TEST: return (8); 1810Sstevel@tonic-gate default: return (-1); 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate #define CMD2INDEX(c) _cmd2index(c) 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate static struct dr_state_trans { 1880Sstevel@tonic-gate int x_cmd; 1890Sstevel@tonic-gate struct { 1900Sstevel@tonic-gate int x_rv; /* return value of pre_op */ 1910Sstevel@tonic-gate int x_err; /* error, if any */ 1920Sstevel@tonic-gate } x_op[DR_STATE_MAX]; 1930Sstevel@tonic-gate } dr_state_transition[] = { 1940Sstevel@tonic-gate { SBD_CMD_CONNECT, 1950Sstevel@tonic-gate { 1960Sstevel@tonic-gate { 0, 0 }, /* empty */ 1970Sstevel@tonic-gate { 0, 0 }, /* occupied */ 1980Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 1990Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2000Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2010Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2020Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2030Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2040Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate }, 2070Sstevel@tonic-gate { SBD_CMD_DISCONNECT, 2080Sstevel@tonic-gate { 2090Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2100Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2110Sstevel@tonic-gate { 0, 0 }, /* connected */ 2120Sstevel@tonic-gate { 0, 0 }, /* unconfigured */ 2130Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2140Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2150Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2160Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2170Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate }, 2200Sstevel@tonic-gate { SBD_CMD_CONFIGURE, 2210Sstevel@tonic-gate { 2220Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2230Sstevel@tonic-gate { -1, ESBD_STATE }, /* occupied */ 2240Sstevel@tonic-gate { 0, 0 }, /* connected */ 2250Sstevel@tonic-gate { 0, 0 }, /* unconfigured */ 2260Sstevel@tonic-gate { 0, 0 }, /* partial */ 2270Sstevel@tonic-gate { 0, 0 }, /* configured */ 2280Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2290Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2300Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2310Sstevel@tonic-gate } 2320Sstevel@tonic-gate }, 2330Sstevel@tonic-gate { SBD_CMD_UNCONFIGURE, 2340Sstevel@tonic-gate { 2350Sstevel@tonic-gate { -1, ESBD_STATE }, /* empty */ 2360Sstevel@tonic-gate { -1, ESBD_STATE }, /* occupied */ 2370Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2380Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2390Sstevel@tonic-gate { 0, 0 }, /* partial */ 2400Sstevel@tonic-gate { 0, 0 }, /* configured */ 2410Sstevel@tonic-gate { 0, 0 }, /* release */ 2420Sstevel@tonic-gate { 0, 0 }, /* unreferenced */ 2430Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2440Sstevel@tonic-gate } 2450Sstevel@tonic-gate }, 2460Sstevel@tonic-gate { SBD_CMD_ASSIGN, 2470Sstevel@tonic-gate { 2480Sstevel@tonic-gate { 0, 0 }, /* empty */ 2490Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2500Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2510Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2520Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2530Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2540Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2550Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2560Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate }, 2590Sstevel@tonic-gate { SBD_CMD_UNASSIGN, 2600Sstevel@tonic-gate { 2610Sstevel@tonic-gate { 0, 0 }, /* empty */ 2620Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2630Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2640Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2650Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2660Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2670Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2680Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2690Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2700Sstevel@tonic-gate } 2710Sstevel@tonic-gate }, 2720Sstevel@tonic-gate { SBD_CMD_POWERON, 2730Sstevel@tonic-gate { 2740Sstevel@tonic-gate { 0, 0 }, /* empty */ 2750Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2760Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2770Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2780Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2790Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2800Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2810Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2820Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate }, 2850Sstevel@tonic-gate { SBD_CMD_POWEROFF, 2860Sstevel@tonic-gate { 2870Sstevel@tonic-gate { 0, 0 }, /* empty */ 2880Sstevel@tonic-gate { 0, 0 }, /* occupied */ 2890Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 2900Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 2910Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 2920Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 2930Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 2940Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 2950Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate }, 2980Sstevel@tonic-gate { SBD_CMD_TEST, 2990Sstevel@tonic-gate { 3000Sstevel@tonic-gate { 0, 0 }, /* empty */ 3010Sstevel@tonic-gate { 0, 0 }, /* occupied */ 3020Sstevel@tonic-gate { -1, ESBD_STATE }, /* connected */ 3030Sstevel@tonic-gate { -1, ESBD_STATE }, /* unconfigured */ 3040Sstevel@tonic-gate { -1, ESBD_STATE }, /* partial */ 3050Sstevel@tonic-gate { -1, ESBD_STATE }, /* configured */ 3060Sstevel@tonic-gate { -1, ESBD_STATE }, /* release */ 3070Sstevel@tonic-gate { -1, ESBD_STATE }, /* unreferenced */ 3080Sstevel@tonic-gate { -1, ESBD_FATAL_STATE }, /* fatal */ 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate }, 3110Sstevel@tonic-gate }; 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * Global R/W lock to synchronize access across 3150Sstevel@tonic-gate * multiple boards. Users wanting multi-board access 3160Sstevel@tonic-gate * must grab WRITE lock, others must grab READ lock. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate krwlock_t dr_grwlock; 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * Head of the boardlist used as a reference point for 3220Sstevel@tonic-gate * locating board structs. 3230Sstevel@tonic-gate * TODO: eliminate dr_boardlist 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate dr_board_t *dr_boardlist; 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* 3280Sstevel@tonic-gate * DR support functions. 3290Sstevel@tonic-gate */ 3300Sstevel@tonic-gate static dr_devset_t dr_dev2devset(sbd_comp_id_t *cid); 3310Sstevel@tonic-gate static int dr_check_transition(dr_board_t *bp, 3320Sstevel@tonic-gate dr_devset_t *devsetp, 3330Sstevel@tonic-gate struct dr_state_trans *transp, 3340Sstevel@tonic-gate int cmd); 3350Sstevel@tonic-gate static int dr_check_unit_attached(dr_common_unit_t *dp); 3360Sstevel@tonic-gate static sbd_error_t *dr_init_devlists(dr_board_t *bp); 3370Sstevel@tonic-gate static void dr_board_discovery(dr_board_t *bp); 3380Sstevel@tonic-gate static int dr_board_init(dr_board_t *bp, dev_info_t *dip, 3390Sstevel@tonic-gate int bd); 3400Sstevel@tonic-gate static void dr_board_destroy(dr_board_t *bp); 3410Sstevel@tonic-gate static void dr_board_transition(dr_board_t *bp, dr_state_t st); 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /* 3440Sstevel@tonic-gate * DR driver (DDI) entry points. 3450Sstevel@tonic-gate */ 3460Sstevel@tonic-gate static int dr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, 3470Sstevel@tonic-gate void *arg, void **result); 3480Sstevel@tonic-gate static int dr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 3490Sstevel@tonic-gate static int dr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 3500Sstevel@tonic-gate static int dr_probe(dev_info_t *dip); 3510Sstevel@tonic-gate static int dr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 3520Sstevel@tonic-gate cred_t *cred_p, int *rval_p); 3530Sstevel@tonic-gate static int dr_close(dev_t dev, int flag, int otyp, cred_t *cred_p); 3540Sstevel@tonic-gate static int dr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p); 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /* 3570Sstevel@tonic-gate * DR command processing operations. 3580Sstevel@tonic-gate */ 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate static int dr_copyin_iocmd(dr_handle_t *hp); 3610Sstevel@tonic-gate static int dr_copyout_iocmd(dr_handle_t *hp); 3620Sstevel@tonic-gate static int dr_copyout_errs(dr_handle_t *hp); 3630Sstevel@tonic-gate static int dr_pre_op(dr_handle_t *hp); 3640Sstevel@tonic-gate static int dr_post_op(dr_handle_t *hp); 3650Sstevel@tonic-gate static int dr_exec_op(dr_handle_t *hp); 3660Sstevel@tonic-gate static void dr_assign_board(dr_handle_t *hp); 3670Sstevel@tonic-gate static void dr_unassign_board(dr_handle_t *hp); 3680Sstevel@tonic-gate static void dr_connect(dr_handle_t *hp); 3690Sstevel@tonic-gate static int dr_disconnect(dr_handle_t *hp); 3700Sstevel@tonic-gate static void dr_dev_configure(dr_handle_t *hp); 3710Sstevel@tonic-gate static void dr_dev_release(dr_handle_t *hp); 3720Sstevel@tonic-gate static int dr_dev_unconfigure(dr_handle_t *hp); 3730Sstevel@tonic-gate static void dr_dev_cancel(dr_handle_t *hp); 3740Sstevel@tonic-gate static int dr_dev_status(dr_handle_t *hp); 3750Sstevel@tonic-gate static int dr_get_ncm(dr_handle_t *hp); 3760Sstevel@tonic-gate static int dr_pt_ioctl(dr_handle_t *hp); 3770Sstevel@tonic-gate static void dr_poweron_board(dr_handle_t *hp); 3780Sstevel@tonic-gate static void dr_poweroff_board(dr_handle_t *hp); 3790Sstevel@tonic-gate static void dr_test_board(dr_handle_t *hp); 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Autoconfiguration data structures 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate struct cb_ops dr_cb_ops = { 3880Sstevel@tonic-gate dr_open, /* open */ 3890Sstevel@tonic-gate dr_close, /* close */ 3900Sstevel@tonic-gate nodev, /* strategy */ 3910Sstevel@tonic-gate nodev, /* print */ 3920Sstevel@tonic-gate nodev, /* dump */ 3930Sstevel@tonic-gate nodev, /* read */ 3940Sstevel@tonic-gate nodev, /* write */ 3950Sstevel@tonic-gate dr_ioctl, /* ioctl */ 3960Sstevel@tonic-gate nodev, /* devmap */ 3970Sstevel@tonic-gate nodev, /* mmap */ 3980Sstevel@tonic-gate nodev, /* segmap */ 3990Sstevel@tonic-gate nochpoll, /* chpoll */ 4000Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 4010Sstevel@tonic-gate NULL, /* struct streamtab */ 4020Sstevel@tonic-gate D_NEW | D_MP | D_MTSAFE, /* compatibility flags */ 4030Sstevel@tonic-gate CB_REV, /* Rev */ 4040Sstevel@tonic-gate nodev, /* cb_aread */ 4050Sstevel@tonic-gate nodev /* cb_awrite */ 4060Sstevel@tonic-gate }; 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate struct dev_ops dr_dev_ops = { 4090Sstevel@tonic-gate DEVO_REV, /* build version */ 4100Sstevel@tonic-gate 0, /* dev ref count */ 4110Sstevel@tonic-gate dr_getinfo, /* getinfo */ 4120Sstevel@tonic-gate nulldev, /* identify */ 4130Sstevel@tonic-gate dr_probe, /* probe */ 4140Sstevel@tonic-gate dr_attach, /* attach */ 4150Sstevel@tonic-gate dr_detach, /* detach */ 4160Sstevel@tonic-gate nodev, /* reset */ 4170Sstevel@tonic-gate &dr_cb_ops, /* cb_ops */ 4180Sstevel@tonic-gate (struct bus_ops *)NULL, /* bus ops */ 4190Sstevel@tonic-gate NULL /* power */ 4200Sstevel@tonic-gate }; 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate extern struct mod_ops mod_driverops; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate static struct modldrv modldrv = { 4250Sstevel@tonic-gate &mod_driverops, 4260Sstevel@tonic-gate "Dynamic Reconfiguration %I%", 4270Sstevel@tonic-gate &dr_dev_ops 4280Sstevel@tonic-gate }; 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate static struct modlinkage modlinkage = { 4310Sstevel@tonic-gate MODREV_1, 4320Sstevel@tonic-gate (void *)&modldrv, 4330Sstevel@tonic-gate NULL 4340Sstevel@tonic-gate }; 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* 4370Sstevel@tonic-gate * Driver entry points. 4380Sstevel@tonic-gate */ 4390Sstevel@tonic-gate int 4400Sstevel@tonic-gate _init(void) 4410Sstevel@tonic-gate { 4420Sstevel@tonic-gate int err; 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* 4450Sstevel@tonic-gate * If you need to support multiple nodes (instances), then 4460Sstevel@tonic-gate * whatever the maximum number of supported nodes is would 4470Sstevel@tonic-gate * need to passed as the third parameter to ddi_soft_state_init(). 4480Sstevel@tonic-gate * Alternative would be to dynamically fini and re-init the 4490Sstevel@tonic-gate * soft state structure each time a node is attached. 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate err = ddi_soft_state_init((void **)&dr_g.softsp, 452*1772Sjl139090 sizeof (dr_softstate_t), 1); 4530Sstevel@tonic-gate if (err) 4540Sstevel@tonic-gate return (err); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate mutex_init(&dr_g.lock, NULL, MUTEX_DRIVER, NULL); 4570Sstevel@tonic-gate rw_init(&dr_grwlock, NULL, RW_DEFAULT, NULL); 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate return (mod_install(&modlinkage)); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate int 4630Sstevel@tonic-gate _fini(void) 4640Sstevel@tonic-gate { 4650Sstevel@tonic-gate int err; 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate if ((err = mod_remove(&modlinkage)) != 0) 4680Sstevel@tonic-gate return (err); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate mutex_destroy(&dr_g.lock); 4710Sstevel@tonic-gate rw_destroy(&dr_grwlock); 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate ddi_soft_state_fini((void **)&dr_g.softsp); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate return (0); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate int 4790Sstevel@tonic-gate _info(struct modinfo *modinfop) 4800Sstevel@tonic-gate { 4810Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4820Sstevel@tonic-gate } 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate /*ARGSUSED1*/ 4850Sstevel@tonic-gate static int 4860Sstevel@tonic-gate dr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p) 4870Sstevel@tonic-gate { 4880Sstevel@tonic-gate int instance; 4890Sstevel@tonic-gate dr_softstate_t *softsp; 4900Sstevel@tonic-gate dr_board_t *bp; 4910Sstevel@tonic-gate /* 4920Sstevel@tonic-gate * Don't open unless we've attached. 4930Sstevel@tonic-gate */ 4940Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(*dev)); 4950Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 4960Sstevel@tonic-gate if (softsp == NULL) 4970Sstevel@tonic-gate return (ENXIO); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate mutex_enter(&softsp->i_lock); 5000Sstevel@tonic-gate if (!softsp->dr_initialized) { 5010Sstevel@tonic-gate int bd; 5020Sstevel@tonic-gate int rv = 0; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate bp = softsp->boards; 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate /* initialize each array element */ 5070Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++, bp++) { 5080Sstevel@tonic-gate rv = dr_board_init(bp, softsp->dip, bd); 5090Sstevel@tonic-gate if (rv) 5100Sstevel@tonic-gate break; 5110Sstevel@tonic-gate } 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate if (rv == 0) { 5140Sstevel@tonic-gate softsp->dr_initialized = 1; 5150Sstevel@tonic-gate } else { 5160Sstevel@tonic-gate /* destroy elements initialized thus far */ 5170Sstevel@tonic-gate while (--bp >= softsp->boards) 5180Sstevel@tonic-gate dr_board_destroy(bp); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* TODO: should this be another errno val ? */ 5220Sstevel@tonic-gate mutex_exit(&softsp->i_lock); 5230Sstevel@tonic-gate return (ENXIO); 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate } 5260Sstevel@tonic-gate mutex_exit(&softsp->i_lock); 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate bp = &softsp->boards[DR_MINOR2BNUM(getminor(*dev))]; 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate /* 5310Sstevel@tonic-gate * prevent opening of a dyn-ap for a board 5320Sstevel@tonic-gate * that does not exist 5330Sstevel@tonic-gate */ 5340Sstevel@tonic-gate if (!bp->b_assigned) { 5350Sstevel@tonic-gate if (drmach_board_lookup(bp->b_num, &bp->b_id) != 0) 5360Sstevel@tonic-gate return (ENODEV); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate return (0); 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate /*ARGSUSED*/ 5430Sstevel@tonic-gate static int 5440Sstevel@tonic-gate dr_close(dev_t dev, int flag, int otyp, cred_t *cred_p) 5450Sstevel@tonic-gate { 5460Sstevel@tonic-gate return (0); 5470Sstevel@tonic-gate } 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate /* 550*1772Sjl139090 * Enable/disable DR features. 5510Sstevel@tonic-gate */ 5520Sstevel@tonic-gate int dr_enable = 1; 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate /*ARGSUSED3*/ 5550Sstevel@tonic-gate static int 5560Sstevel@tonic-gate dr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 5570Sstevel@tonic-gate cred_t *cred_p, int *rval_p) 5580Sstevel@tonic-gate { 5590Sstevel@tonic-gate static int dr_dev_type_to_nt(char *); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate int rv = 0; 5620Sstevel@tonic-gate int instance; 5630Sstevel@tonic-gate int bd; 5640Sstevel@tonic-gate dr_handle_t *hp; 5650Sstevel@tonic-gate dr_softstate_t *softsp; 5660Sstevel@tonic-gate static fn_t f = "dr_ioctl"; 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate PR_ALL("%s...\n", f); 5690Sstevel@tonic-gate 5700Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(dev)); 5710Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 5720Sstevel@tonic-gate if (softsp == NULL) { 5730Sstevel@tonic-gate cmn_err(CE_WARN, "dr%d: module not yet attached", instance); 5740Sstevel@tonic-gate return (ENXIO); 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate if (!dr_enable) { 5780Sstevel@tonic-gate switch (cmd) { 5790Sstevel@tonic-gate case SBD_CMD_STATUS: 5800Sstevel@tonic-gate case SBD_CMD_GETNCM: 5810Sstevel@tonic-gate case SBD_CMD_PASSTHRU: 5820Sstevel@tonic-gate break; 5830Sstevel@tonic-gate default: 5840Sstevel@tonic-gate return (ENOTSUP); 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate bd = DR_MINOR2BNUM(getminor(dev)); 5890Sstevel@tonic-gate if (bd >= MAX_BOARDS) 5900Sstevel@tonic-gate return (ENXIO); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate /* get and initialize storage for new handle */ 5930Sstevel@tonic-gate hp = GETSTRUCT(dr_handle_t, 1); 5940Sstevel@tonic-gate hp->h_bd = &softsp->boards[bd]; 5950Sstevel@tonic-gate hp->h_err = NULL; 5960Sstevel@tonic-gate hp->h_dev = getminor(dev); 5970Sstevel@tonic-gate hp->h_cmd = cmd; 5980Sstevel@tonic-gate hp->h_mode = mode; 5990Sstevel@tonic-gate hp->h_iap = (sbd_ioctl_arg_t *)arg; 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* copy sbd command into handle */ 6020Sstevel@tonic-gate rv = dr_copyin_iocmd(hp); 6030Sstevel@tonic-gate if (rv) { 6040Sstevel@tonic-gate FREESTRUCT(hp, dr_handle_t, 1); 6050Sstevel@tonic-gate return (EINVAL); 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate /* translate canonical name to component type */ 6090Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_name[0] != '\0') { 6100Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_type = 6110Sstevel@tonic-gate dr_dev_type_to_nt(hp->h_sbdcmd.cmd_cm.c_id.c_name); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate PR_ALL("%s: c_name = %s, c_type = %d\n", 6140Sstevel@tonic-gate f, 6150Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_name, 6160Sstevel@tonic-gate hp->h_sbdcmd.cmd_cm.c_id.c_type); 6170Sstevel@tonic-gate } else { 6180Sstevel@tonic-gate /*EMPTY*/ 6190Sstevel@tonic-gate PR_ALL("%s: c_name is NULL\n", f); 6200Sstevel@tonic-gate } 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate /* determine scope of operation */ 6230Sstevel@tonic-gate hp->h_devset = dr_dev2devset(&hp->h_sbdcmd.cmd_cm.c_id); 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate switch (hp->h_cmd) { 6260Sstevel@tonic-gate case SBD_CMD_STATUS: 6270Sstevel@tonic-gate case SBD_CMD_GETNCM: 6280Sstevel@tonic-gate /* no locks needed for these commands */ 6290Sstevel@tonic-gate break; 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate default: 6320Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 6330Sstevel@tonic-gate mutex_enter(&hp->h_bd->b_lock); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate /* 6360Sstevel@tonic-gate * If we're dealing with memory at all, then we have 6370Sstevel@tonic-gate * to keep the "exclusive" global lock held. This is 6380Sstevel@tonic-gate * necessary since we will probably need to look at 6390Sstevel@tonic-gate * multiple board structs. Otherwise, we only have 6400Sstevel@tonic-gate * to deal with the board in question and so can drop 6410Sstevel@tonic-gate * the global lock to "shared". 6420Sstevel@tonic-gate */ 6430Sstevel@tonic-gate rv = DEVSET_IN_SET(hp->h_devset, SBD_COMP_MEM, DEVSET_ANYUNIT); 6440Sstevel@tonic-gate if (rv == 0) 6450Sstevel@tonic-gate rw_downgrade(&dr_grwlock); 6460Sstevel@tonic-gate break; 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate rv = 0; 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate if (rv == 0) 6510Sstevel@tonic-gate rv = dr_pre_op(hp); 6520Sstevel@tonic-gate if (rv == 0) 6530Sstevel@tonic-gate rv = dr_exec_op(hp); 6540Sstevel@tonic-gate if (rv == 0) 6550Sstevel@tonic-gate rv = dr_post_op(hp); 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate if (rv == -1) 6580Sstevel@tonic-gate rv = EIO; 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate if (hp->h_err != NULL) 6610Sstevel@tonic-gate if (!(rv = dr_copyout_errs(hp))) 6620Sstevel@tonic-gate rv = EIO; 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate /* undo locking, if any, done before dr_pre_op */ 6650Sstevel@tonic-gate switch (hp->h_cmd) { 6660Sstevel@tonic-gate case SBD_CMD_STATUS: 6670Sstevel@tonic-gate case SBD_CMD_GETNCM: 6680Sstevel@tonic-gate break; 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate case SBD_CMD_ASSIGN: 6710Sstevel@tonic-gate case SBD_CMD_UNASSIGN: 6720Sstevel@tonic-gate case SBD_CMD_POWERON: 6730Sstevel@tonic-gate case SBD_CMD_POWEROFF: 6740Sstevel@tonic-gate case SBD_CMD_CONNECT: 6750Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 6760Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 6770Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 6780Sstevel@tonic-gate /* Board changed state. Log a sysevent. */ 6790Sstevel@tonic-gate if (rv == 0) 6800Sstevel@tonic-gate (void) drmach_log_sysevent(hp->h_bd->b_num, "", 681*1772Sjl139090 SE_SLEEP, 1); 6820Sstevel@tonic-gate /* Fall through */ 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate default: 6850Sstevel@tonic-gate mutex_exit(&hp->h_bd->b_lock); 6860Sstevel@tonic-gate rw_exit(&dr_grwlock); 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate if (hp->h_opts.size != 0) 6900Sstevel@tonic-gate FREESTRUCT(hp->h_opts.copts, char, hp->h_opts.size); 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate FREESTRUCT(hp, dr_handle_t, 1); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate return (rv); 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate /*ARGSUSED*/ 6980Sstevel@tonic-gate static int 6990Sstevel@tonic-gate dr_probe(dev_info_t *dip) 7000Sstevel@tonic-gate { 7010Sstevel@tonic-gate return (DDI_PROBE_SUCCESS); 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate static int 7050Sstevel@tonic-gate dr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 7060Sstevel@tonic-gate { 7070Sstevel@tonic-gate int rv, rv2; 7080Sstevel@tonic-gate int bd; 7090Sstevel@tonic-gate int instance; 7100Sstevel@tonic-gate sbd_error_t *err; 7110Sstevel@tonic-gate dr_softstate_t *softsp; 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate instance = ddi_get_instance(dip); 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate switch (cmd) { 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate case DDI_ATTACH: 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate rv = ddi_soft_state_zalloc(dr_g.softsp, instance); 7220Sstevel@tonic-gate if (rv != DDI_SUCCESS) { 7230Sstevel@tonic-gate cmn_err(CE_WARN, "dr%d: failed to alloc soft-state", 7240Sstevel@tonic-gate instance); 7250Sstevel@tonic-gate return (DDI_FAILURE); 7260Sstevel@tonic-gate } 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate /* initialize softstate structure */ 7290Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 7300Sstevel@tonic-gate softsp->dip = dip; 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate mutex_init(&softsp->i_lock, NULL, MUTEX_DRIVER, NULL); 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate /* allocate board array (aka boardlist) */ 7350Sstevel@tonic-gate softsp->boards = GETSTRUCT(dr_board_t, MAX_BOARDS); 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 7380Sstevel@tonic-gate dr_boardlist = softsp->boards; 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* initialize each array element */ 7410Sstevel@tonic-gate rv = DDI_SUCCESS; 7420Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++) { 7430Sstevel@tonic-gate dr_board_t *bp = &softsp->boards[bd]; 7440Sstevel@tonic-gate char *p, *name; 7450Sstevel@tonic-gate int l, minor_num; 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate /* 7480Sstevel@tonic-gate * initialized board attachment point path 7490Sstevel@tonic-gate * (relative to pseudo) in a form immediately 7500Sstevel@tonic-gate * reusable as an cfgadm command argument. 7510Sstevel@tonic-gate * TODO: clean this up 7520Sstevel@tonic-gate */ 7530Sstevel@tonic-gate p = bp->b_path; 7540Sstevel@tonic-gate l = sizeof (bp->b_path); 7550Sstevel@tonic-gate (void) snprintf(p, l, "dr@%d:", instance); 7560Sstevel@tonic-gate while (*p != '\0') { 7570Sstevel@tonic-gate l--; 7580Sstevel@tonic-gate p++; 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate name = p; 7620Sstevel@tonic-gate err = drmach_board_name(bd, p, l); 7630Sstevel@tonic-gate if (err) { 7640Sstevel@tonic-gate sbd_err_clear(&err); 7650Sstevel@tonic-gate rv = DDI_FAILURE; 7660Sstevel@tonic-gate break; 7670Sstevel@tonic-gate } 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate minor_num = DR_MAKE_MINOR(instance, bd); 7700Sstevel@tonic-gate rv = ddi_create_minor_node(dip, name, S_IFCHR, 7710Sstevel@tonic-gate minor_num, DDI_NT_SBD_ATTACHMENT_POINT, NULL); 7720Sstevel@tonic-gate if (rv != DDI_SUCCESS) 7730Sstevel@tonic-gate rv = DDI_FAILURE; 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate if (rv == DDI_SUCCESS) { 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * Announce the node's presence. 7790Sstevel@tonic-gate */ 7800Sstevel@tonic-gate ddi_report_dev(dip); 7810Sstevel@tonic-gate } else { 7820Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate /* 7850Sstevel@tonic-gate * Init registered unsafe devs. 7860Sstevel@tonic-gate */ 7870Sstevel@tonic-gate dr_unsafe_devs.devnames = NULL; 7880Sstevel@tonic-gate rv2 = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 7890Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, 7900Sstevel@tonic-gate "unsupported-io-drivers", &dr_unsafe_devs.devnames, 7910Sstevel@tonic-gate &dr_unsafe_devs.ndevs); 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate if (rv2 != DDI_PROP_SUCCESS) 7940Sstevel@tonic-gate dr_unsafe_devs.ndevs = 0; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate rw_exit(&dr_grwlock); 7970Sstevel@tonic-gate return (rv); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate default: 8000Sstevel@tonic-gate return (DDI_FAILURE); 8010Sstevel@tonic-gate } 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate /*NOTREACHED*/ 8040Sstevel@tonic-gate } 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate static int 8070Sstevel@tonic-gate dr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 8080Sstevel@tonic-gate { 8090Sstevel@tonic-gate int instance; 8100Sstevel@tonic-gate dr_softstate_t *softsp; 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate switch (cmd) { 8130Sstevel@tonic-gate case DDI_DETACH: 8140Sstevel@tonic-gate if (!dr_modunload_okay) 8150Sstevel@tonic-gate return (DDI_FAILURE); 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate rw_enter(&dr_grwlock, RW_WRITER); 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate instance = ddi_get_instance(dip); 8200Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 8210Sstevel@tonic-gate 8220Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 8230Sstevel@tonic-gate ASSERT(softsp->boards == dr_boardlist); 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate /* remove all minor nodes */ 8260Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate if (softsp->dr_initialized) { 8290Sstevel@tonic-gate int bd; 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate for (bd = 0; bd < MAX_BOARDS; bd++) 8320Sstevel@tonic-gate dr_board_destroy(&softsp->boards[bd]); 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate FREESTRUCT(softsp->boards, dr_board_t, MAX_BOARDS); 8360Sstevel@tonic-gate mutex_destroy(&softsp->i_lock); 8370Sstevel@tonic-gate ddi_soft_state_free(dr_g.softsp, instance); 8380Sstevel@tonic-gate 8390Sstevel@tonic-gate rw_exit(&dr_grwlock); 8400Sstevel@tonic-gate return (DDI_SUCCESS); 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate default: 8430Sstevel@tonic-gate return (DDI_FAILURE); 8440Sstevel@tonic-gate } 8450Sstevel@tonic-gate /*NOTREACHED*/ 8460Sstevel@tonic-gate } 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate static int 8490Sstevel@tonic-gate dr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 8500Sstevel@tonic-gate { 8510Sstevel@tonic-gate _NOTE(ARGUNUSED(dip)) 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate dev_t dev = (dev_t)arg; 8540Sstevel@tonic-gate int instance, error; 8550Sstevel@tonic-gate dr_softstate_t *softsp; 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate *result = NULL; 8580Sstevel@tonic-gate error = DDI_SUCCESS; 8590Sstevel@tonic-gate instance = DR_MINOR2INST(getminor(dev)); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate switch (cmd) { 8620Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 8630Sstevel@tonic-gate softsp = ddi_get_soft_state(dr_g.softsp, instance); 8640Sstevel@tonic-gate if (softsp == NULL) 8650Sstevel@tonic-gate return (DDI_FAILURE); 8660Sstevel@tonic-gate *result = (void *)softsp->dip; 8670Sstevel@tonic-gate break; 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 870930Smathue *result = (void *)(uintptr_t)instance; 8710Sstevel@tonic-gate break; 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate default: 8740Sstevel@tonic-gate error = DDI_FAILURE; 8750Sstevel@tonic-gate break; 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate return (error); 8790Sstevel@tonic-gate } 8800Sstevel@tonic-gate 8810Sstevel@tonic-gate /* 8820Sstevel@tonic-gate * DR operations. 8830Sstevel@tonic-gate */ 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate static int 8860Sstevel@tonic-gate dr_copyin_iocmd(dr_handle_t *hp) 8870Sstevel@tonic-gate { 8880Sstevel@tonic-gate static fn_t f = "dr_copyin_iocmd"; 8890Sstevel@tonic-gate sbd_cmd_t *scp = &hp->h_sbdcmd; 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate if (hp->h_iap == NULL) 8920Sstevel@tonic-gate return (EINVAL); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate bzero((caddr_t)scp, sizeof (sbd_cmd_t)); 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 8970Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 8980Sstevel@tonic-gate sbd_cmd32_t scmd32; 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate bzero((caddr_t)&scmd32, sizeof (sbd_cmd32_t)); 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate if (ddi_copyin((void *)hp->h_iap, (void *)&scmd32, 903*1772Sjl139090 sizeof (sbd_cmd32_t), hp->h_mode)) { 9040Sstevel@tonic-gate cmn_err(CE_WARN, 9050Sstevel@tonic-gate "%s: (32bit) failed to copyin " 9060Sstevel@tonic-gate "sbdcmd-struct", f); 9070Sstevel@tonic-gate return (EFAULT); 9080Sstevel@tonic-gate } 9090Sstevel@tonic-gate scp->cmd_cm.c_id.c_type = scmd32.cmd_cm.c_id.c_type; 9100Sstevel@tonic-gate scp->cmd_cm.c_id.c_unit = scmd32.cmd_cm.c_id.c_unit; 9110Sstevel@tonic-gate bcopy(&scmd32.cmd_cm.c_id.c_name[0], 9120Sstevel@tonic-gate &scp->cmd_cm.c_id.c_name[0], OBP_MAXPROPNAME); 9130Sstevel@tonic-gate scp->cmd_cm.c_flags = scmd32.cmd_cm.c_flags; 9140Sstevel@tonic-gate scp->cmd_cm.c_len = scmd32.cmd_cm.c_len; 915930Smathue scp->cmd_cm.c_opts = (caddr_t)(uintptr_t)scmd32.cmd_cm.c_opts; 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate switch (hp->h_cmd) { 9180Sstevel@tonic-gate case SBD_CMD_STATUS: 9190Sstevel@tonic-gate scp->cmd_stat.s_nbytes = scmd32.cmd_stat.s_nbytes; 9200Sstevel@tonic-gate scp->cmd_stat.s_statp = 921930Smathue (caddr_t)(uintptr_t)scmd32.cmd_stat.s_statp; 9220Sstevel@tonic-gate break; 9230Sstevel@tonic-gate default: 9240Sstevel@tonic-gate break; 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate } 9270Sstevel@tonic-gate } else 9280Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 9290Sstevel@tonic-gate if (ddi_copyin((void *)hp->h_iap, (void *)scp, 930*1772Sjl139090 sizeof (sbd_cmd_t), hp->h_mode) != 0) { 9310Sstevel@tonic-gate cmn_err(CE_WARN, 9320Sstevel@tonic-gate "%s: failed to copyin sbdcmd-struct", f); 9330Sstevel@tonic-gate return (EFAULT); 9340Sstevel@tonic-gate } 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate if ((hp->h_opts.size = scp->cmd_cm.c_len) != 0) { 9370Sstevel@tonic-gate hp->h_opts.copts = GETSTRUCT(char, scp->cmd_cm.c_len + 1); 9380Sstevel@tonic-gate ++hp->h_opts.size; 9390Sstevel@tonic-gate if (ddi_copyin((void *)scp->cmd_cm.c_opts, 9400Sstevel@tonic-gate (void *)hp->h_opts.copts, 9410Sstevel@tonic-gate scp->cmd_cm.c_len, hp->h_mode) != 0) { 9420Sstevel@tonic-gate cmn_err(CE_WARN, "%s: failed to copyin options", f); 9430Sstevel@tonic-gate return (EFAULT); 9440Sstevel@tonic-gate } 9450Sstevel@tonic-gate } 9460Sstevel@tonic-gate return (0); 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate static int 9500Sstevel@tonic-gate dr_copyout_iocmd(dr_handle_t *hp) 9510Sstevel@tonic-gate { 9520Sstevel@tonic-gate static fn_t f = "dr_copyout_iocmd"; 9530Sstevel@tonic-gate sbd_cmd_t *scp = &hp->h_sbdcmd; 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate if (hp->h_iap == NULL) 9560Sstevel@tonic-gate return (EINVAL); 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 9590Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 9600Sstevel@tonic-gate sbd_cmd32_t scmd32; 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate scmd32.cmd_cm.c_id.c_type = scp->cmd_cm.c_id.c_type; 9630Sstevel@tonic-gate scmd32.cmd_cm.c_id.c_unit = scp->cmd_cm.c_id.c_unit; 9640Sstevel@tonic-gate bcopy(&scp->cmd_cm.c_id.c_name[0], 9650Sstevel@tonic-gate &scmd32.cmd_cm.c_id.c_name[0], OBP_MAXPROPNAME); 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate scmd32.cmd_cm.c_flags = scp->cmd_cm.c_flags; 9680Sstevel@tonic-gate scmd32.cmd_cm.c_len = scp->cmd_cm.c_len; 969930Smathue scmd32.cmd_cm.c_opts = (caddr32_t)(uintptr_t)scp->cmd_cm.c_opts; 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate switch (hp->h_cmd) { 9720Sstevel@tonic-gate case SBD_CMD_GETNCM: 9730Sstevel@tonic-gate scmd32.cmd_getncm.g_ncm = scp->cmd_getncm.g_ncm; 9740Sstevel@tonic-gate break; 9750Sstevel@tonic-gate default: 9760Sstevel@tonic-gate break; 9770Sstevel@tonic-gate } 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate if (ddi_copyout((void *)&scmd32, (void *)hp->h_iap, 980*1772Sjl139090 sizeof (sbd_cmd32_t), hp->h_mode)) { 9810Sstevel@tonic-gate cmn_err(CE_WARN, 9820Sstevel@tonic-gate "%s: (32bit) failed to copyout " 9830Sstevel@tonic-gate "sbdcmd-struct", f); 9840Sstevel@tonic-gate return (EFAULT); 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate } else 9870Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 9880Sstevel@tonic-gate if (ddi_copyout((void *)scp, (void *)hp->h_iap, 989*1772Sjl139090 sizeof (sbd_cmd_t), hp->h_mode) != 0) { 9900Sstevel@tonic-gate cmn_err(CE_WARN, 9910Sstevel@tonic-gate "%s: failed to copyout sbdcmd-struct", f); 9920Sstevel@tonic-gate return (EFAULT); 9930Sstevel@tonic-gate } 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate return (0); 9960Sstevel@tonic-gate } 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate static int 9990Sstevel@tonic-gate dr_copyout_errs(dr_handle_t *hp) 10000Sstevel@tonic-gate { 10010Sstevel@tonic-gate static fn_t f = "dr_copyout_errs"; 10020Sstevel@tonic-gate 10030Sstevel@tonic-gate if (hp->h_err == NULL) 10040Sstevel@tonic-gate return (0); 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate if (hp->h_err->e_code) { 10070Sstevel@tonic-gate PR_ALL("%s: error %d %s", 10080Sstevel@tonic-gate f, hp->h_err->e_code, hp->h_err->e_rsc); 10090Sstevel@tonic-gate } 10100Sstevel@tonic-gate 10110Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 10120Sstevel@tonic-gate if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) { 10130Sstevel@tonic-gate sbd_error32_t *serr32p; 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate serr32p = GETSTRUCT(sbd_error32_t, 1); 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate serr32p->e_code = hp->h_err->e_code; 10180Sstevel@tonic-gate bcopy(&hp->h_err->e_rsc[0], &serr32p->e_rsc[0], 10190Sstevel@tonic-gate MAXPATHLEN); 10200Sstevel@tonic-gate if (ddi_copyout((void *)serr32p, 10210Sstevel@tonic-gate (void *)&((sbd_ioctl_arg32_t *)hp->h_iap)->i_err, 1022*1772Sjl139090 sizeof (sbd_error32_t), hp->h_mode)) { 10230Sstevel@tonic-gate cmn_err(CE_WARN, 10240Sstevel@tonic-gate "%s: (32bit) failed to copyout", f); 10250Sstevel@tonic-gate return (EFAULT); 10260Sstevel@tonic-gate } 10270Sstevel@tonic-gate FREESTRUCT(serr32p, sbd_error32_t, 1); 10280Sstevel@tonic-gate } else 10290Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 10300Sstevel@tonic-gate if (ddi_copyout((void *)hp->h_err, 10310Sstevel@tonic-gate (void *)&hp->h_iap->i_err, 1032*1772Sjl139090 sizeof (sbd_error_t), hp->h_mode)) { 10330Sstevel@tonic-gate cmn_err(CE_WARN, 10340Sstevel@tonic-gate "%s: failed to copyout", f); 10350Sstevel@tonic-gate return (EFAULT); 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate sbd_err_clear(&hp->h_err); 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate return (0); 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate 10440Sstevel@tonic-gate /* 10450Sstevel@tonic-gate * pre-op entry point must sbd_err_set_c(), if needed. 10460Sstevel@tonic-gate * Return value of non-zero indicates failure. 10470Sstevel@tonic-gate */ 10480Sstevel@tonic-gate static int 10490Sstevel@tonic-gate dr_pre_op(dr_handle_t *hp) 10500Sstevel@tonic-gate { 10510Sstevel@tonic-gate int rv = 0, t; 10520Sstevel@tonic-gate int cmd, serr = 0; 10530Sstevel@tonic-gate dr_devset_t devset; 10540Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 10550Sstevel@tonic-gate dr_handle_t *shp = hp; 10560Sstevel@tonic-gate static fn_t f = "dr_pre_op"; 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate cmd = hp->h_cmd; 10590Sstevel@tonic-gate devset = shp->h_devset; 10600Sstevel@tonic-gate 1061930Smathue PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd)); 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate hp->h_err = drmach_pre_op(cmd, bp->b_id, &hp->h_opts); 10640Sstevel@tonic-gate if (hp->h_err != NULL) { 10650Sstevel@tonic-gate PR_ALL("drmach_pre_op failed for cmd %s(%d)\n", 10660Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 10670Sstevel@tonic-gate return (-1); 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /* 10710Sstevel@tonic-gate * Check for valid state transitions. 10720Sstevel@tonic-gate */ 10730Sstevel@tonic-gate if ((t = CMD2INDEX(cmd)) != -1) { 10740Sstevel@tonic-gate struct dr_state_trans *transp; 10750Sstevel@tonic-gate int state_err; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate transp = &dr_state_transition[t]; 10780Sstevel@tonic-gate ASSERT(transp->x_cmd == cmd); 10790Sstevel@tonic-gate 10800Sstevel@tonic-gate state_err = dr_check_transition(bp, &devset, transp, cmd); 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate if (state_err < 0) { 10830Sstevel@tonic-gate /* 10840Sstevel@tonic-gate * Invalidate device. 10850Sstevel@tonic-gate */ 10860Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_INVAL, NULL); 10870Sstevel@tonic-gate serr = -1; 10880Sstevel@tonic-gate PR_ALL("%s: invalid devset (0x%x)\n", 10890Sstevel@tonic-gate f, (uint_t)devset); 10900Sstevel@tonic-gate } else if (state_err != 0) { 10910Sstevel@tonic-gate /* 10920Sstevel@tonic-gate * State transition is not a valid one. 10930Sstevel@tonic-gate */ 10940Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, 10950Sstevel@tonic-gate transp->x_op[state_err].x_err, NULL); 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate serr = transp->x_op[state_err].x_rv; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate PR_ALL("%s: invalid state %s(%d) for cmd %s(%d)\n", 11000Sstevel@tonic-gate f, state_str[state_err], state_err, 11010Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 11020Sstevel@tonic-gate } else { 11030Sstevel@tonic-gate shp->h_devset = devset; 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate } 11060Sstevel@tonic-gate 11070Sstevel@tonic-gate if (serr) { 11080Sstevel@tonic-gate rv = -1; 11090Sstevel@tonic-gate } 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate return (rv); 11120Sstevel@tonic-gate } 11130Sstevel@tonic-gate 11140Sstevel@tonic-gate static int 11150Sstevel@tonic-gate dr_post_op(dr_handle_t *hp) 11160Sstevel@tonic-gate { 11170Sstevel@tonic-gate int rv = 0; 11180Sstevel@tonic-gate int cmd; 11190Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 11200Sstevel@tonic-gate static fn_t f = "dr_post_op"; 11210Sstevel@tonic-gate 11220Sstevel@tonic-gate cmd = hp->h_cmd; 11230Sstevel@tonic-gate 1124930Smathue PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd)); 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate /* errors should have been caught by now */ 11270Sstevel@tonic-gate ASSERT(hp->h_err == NULL); 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate hp->h_err = drmach_post_op(cmd, bp->b_id, &hp->h_opts); 11300Sstevel@tonic-gate if (hp->h_err != NULL) { 11310Sstevel@tonic-gate PR_ALL("drmach_post_op failed for cmd %s(%d)\n", 11320Sstevel@tonic-gate SBD_CMD_STR(cmd), cmd); 11330Sstevel@tonic-gate return (-1); 11340Sstevel@tonic-gate } 11350Sstevel@tonic-gate 11360Sstevel@tonic-gate switch (cmd) { 11370Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 11380Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 11390Sstevel@tonic-gate case SBD_CMD_CONNECT: 11400Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 11410Sstevel@tonic-gate case SBD_CMD_GETNCM: 11420Sstevel@tonic-gate case SBD_CMD_STATUS: 11430Sstevel@tonic-gate break; 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate default: 11460Sstevel@tonic-gate break; 11470Sstevel@tonic-gate } 11480Sstevel@tonic-gate 11490Sstevel@tonic-gate return (rv); 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate static int 11530Sstevel@tonic-gate dr_exec_op(dr_handle_t *hp) 11540Sstevel@tonic-gate { 11550Sstevel@tonic-gate int rv = 0; 11560Sstevel@tonic-gate static fn_t f = "dr_exec_op"; 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate /* errors should have been caught by now */ 11590Sstevel@tonic-gate ASSERT(hp->h_err == NULL); 11600Sstevel@tonic-gate 11610Sstevel@tonic-gate switch (hp->h_cmd) { 11620Sstevel@tonic-gate case SBD_CMD_ASSIGN: 11630Sstevel@tonic-gate dr_assign_board(hp); 11640Sstevel@tonic-gate break; 11650Sstevel@tonic-gate 11660Sstevel@tonic-gate case SBD_CMD_UNASSIGN: 11670Sstevel@tonic-gate dr_unassign_board(hp); 11680Sstevel@tonic-gate break; 11690Sstevel@tonic-gate 11700Sstevel@tonic-gate case SBD_CMD_POWEROFF: 11710Sstevel@tonic-gate dr_poweroff_board(hp); 11720Sstevel@tonic-gate break; 11730Sstevel@tonic-gate 11740Sstevel@tonic-gate case SBD_CMD_POWERON: 11750Sstevel@tonic-gate dr_poweron_board(hp); 11760Sstevel@tonic-gate break; 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate case SBD_CMD_TEST: 11790Sstevel@tonic-gate dr_test_board(hp); 11800Sstevel@tonic-gate break; 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate case SBD_CMD_CONNECT: 11830Sstevel@tonic-gate dr_connect(hp); 11840Sstevel@tonic-gate break; 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate case SBD_CMD_CONFIGURE: 11870Sstevel@tonic-gate dr_dev_configure(hp); 11880Sstevel@tonic-gate break; 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate case SBD_CMD_UNCONFIGURE: 11910Sstevel@tonic-gate dr_dev_release(hp); 11920Sstevel@tonic-gate if (hp->h_err == NULL) 11930Sstevel@tonic-gate rv = dr_dev_unconfigure(hp); 11940Sstevel@tonic-gate else 11950Sstevel@tonic-gate dr_dev_cancel(hp); 11960Sstevel@tonic-gate break; 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate case SBD_CMD_DISCONNECT: 11990Sstevel@tonic-gate rv = dr_disconnect(hp); 12000Sstevel@tonic-gate break; 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate case SBD_CMD_STATUS: 12030Sstevel@tonic-gate rv = dr_dev_status(hp); 12040Sstevel@tonic-gate break; 12050Sstevel@tonic-gate 12060Sstevel@tonic-gate case SBD_CMD_GETNCM: 12070Sstevel@tonic-gate hp->h_sbdcmd.cmd_getncm.g_ncm = dr_get_ncm(hp); 12080Sstevel@tonic-gate rv = dr_copyout_iocmd(hp); 12090Sstevel@tonic-gate break; 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate case SBD_CMD_PASSTHRU: 12120Sstevel@tonic-gate rv = dr_pt_ioctl(hp); 12130Sstevel@tonic-gate break; 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate default: 12160Sstevel@tonic-gate cmn_err(CE_WARN, 12170Sstevel@tonic-gate "%s: unknown command (%d)", 12180Sstevel@tonic-gate f, hp->h_cmd); 12190Sstevel@tonic-gate break; 12200Sstevel@tonic-gate } 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate if (hp->h_err != NULL) { 12230Sstevel@tonic-gate rv = -1; 12240Sstevel@tonic-gate } 12250Sstevel@tonic-gate 12260Sstevel@tonic-gate return (rv); 12270Sstevel@tonic-gate } 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate static void 12300Sstevel@tonic-gate dr_assign_board(dr_handle_t *hp) 12310Sstevel@tonic-gate { 12320Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate hp->h_err = drmach_board_assign(bp->b_num, &bp->b_id); 12350Sstevel@tonic-gate if (hp->h_err == NULL) { 12360Sstevel@tonic-gate bp->b_assigned = 1; 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate static void 12410Sstevel@tonic-gate dr_unassign_board(dr_handle_t *hp) 12420Sstevel@tonic-gate { 12430Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate /* 12460Sstevel@tonic-gate * Block out status during unassign. 12470Sstevel@tonic-gate * Not doing cv_wait_sig here as starfire SSP software 12480Sstevel@tonic-gate * ignores unassign failure and removes board from 12490Sstevel@tonic-gate * domain mask causing system panic. 12500Sstevel@tonic-gate * TODO: Change cv_wait to cv_wait_sig when SSP software 12510Sstevel@tonic-gate * handles unassign failure. 12520Sstevel@tonic-gate */ 12530Sstevel@tonic-gate dr_lock_status(bp); 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate hp->h_err = drmach_board_unassign(bp->b_id); 12560Sstevel@tonic-gate if (hp->h_err == NULL) { 12570Sstevel@tonic-gate /* 12580Sstevel@tonic-gate * clear drmachid_t handle; not valid after board unassign 12590Sstevel@tonic-gate */ 12600Sstevel@tonic-gate bp->b_id = 0; 12610Sstevel@tonic-gate bp->b_assigned = 0; 12620Sstevel@tonic-gate } 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate dr_unlock_status(bp); 12650Sstevel@tonic-gate } 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate static void 12680Sstevel@tonic-gate dr_poweron_board(dr_handle_t *hp) 12690Sstevel@tonic-gate { 12700Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate hp->h_err = drmach_board_poweron(bp->b_id); 12730Sstevel@tonic-gate } 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate static void 12760Sstevel@tonic-gate dr_poweroff_board(dr_handle_t *hp) 12770Sstevel@tonic-gate { 12780Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12790Sstevel@tonic-gate 12800Sstevel@tonic-gate hp->h_err = drmach_board_poweroff(bp->b_id); 12810Sstevel@tonic-gate } 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate static void 12840Sstevel@tonic-gate dr_test_board(dr_handle_t *hp) 12850Sstevel@tonic-gate { 12860Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 12870Sstevel@tonic-gate hp->h_err = drmach_board_test(bp->b_id, &hp->h_opts, 12880Sstevel@tonic-gate dr_cmd_flags(hp) & SBD_FLAG_FORCE); 12890Sstevel@tonic-gate } 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate /* 12920Sstevel@tonic-gate * Create and populate the component nodes for a board. Assumes that the 12930Sstevel@tonic-gate * devlists for the board have been initialized. 12940Sstevel@tonic-gate */ 12950Sstevel@tonic-gate static void 12960Sstevel@tonic-gate dr_make_comp_nodes(dr_board_t *bp) { 12970Sstevel@tonic-gate 12980Sstevel@tonic-gate int i; 12990Sstevel@tonic-gate 13000Sstevel@tonic-gate /* 13010Sstevel@tonic-gate * Make nodes for the individual components on the board. 13020Sstevel@tonic-gate * First we need to initialize memory unit data structures of board 13030Sstevel@tonic-gate * structure. 13040Sstevel@tonic-gate */ 13050Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 13060Sstevel@tonic-gate dr_mem_unit_t *mp; 13070Sstevel@tonic-gate 13080Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 13090Sstevel@tonic-gate dr_init_mem_unit(mp); 13100Sstevel@tonic-gate } 13110Sstevel@tonic-gate 13120Sstevel@tonic-gate /* 13130Sstevel@tonic-gate * Initialize cpu unit data structures. 13140Sstevel@tonic-gate */ 13150Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 13160Sstevel@tonic-gate dr_cpu_unit_t *cp; 13170Sstevel@tonic-gate 13180Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 13190Sstevel@tonic-gate dr_init_cpu_unit(cp); 13200Sstevel@tonic-gate } 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate /* 13230Sstevel@tonic-gate * Initialize io unit data structures. 13240Sstevel@tonic-gate */ 13250Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 13260Sstevel@tonic-gate dr_io_unit_t *ip; 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 13290Sstevel@tonic-gate dr_init_io_unit(ip); 13300Sstevel@tonic-gate } 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONNECTED); 13330Sstevel@tonic-gate 13340Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 13350Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 13360Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 13370Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate } 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate /* 13420Sstevel@tonic-gate * Only do work if called to operate on an entire board 13430Sstevel@tonic-gate * which doesn't already have components present. 13440Sstevel@tonic-gate */ 13450Sstevel@tonic-gate static void 13460Sstevel@tonic-gate dr_connect(dr_handle_t *hp) 13470Sstevel@tonic-gate { 13480Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 13490Sstevel@tonic-gate static fn_t f = "dr_connect"; 13500Sstevel@tonic-gate 13510Sstevel@tonic-gate PR_ALL("%s...\n", f); 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp)) { 13540Sstevel@tonic-gate /* 13550Sstevel@tonic-gate * Board already has devices present. 13560Sstevel@tonic-gate */ 1357*1772Sjl139090 PR_ALL("%s: devices already present (0x%lx)\n", 13580Sstevel@tonic-gate f, DR_DEVS_PRESENT(bp)); 13590Sstevel@tonic-gate return; 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate hp->h_err = drmach_board_connect(bp->b_id, &hp->h_opts); 13630Sstevel@tonic-gate if (hp->h_err) 13640Sstevel@tonic-gate return; 13650Sstevel@tonic-gate 13660Sstevel@tonic-gate hp->h_err = dr_init_devlists(bp); 13670Sstevel@tonic-gate if (hp->h_err) 13680Sstevel@tonic-gate return; 13690Sstevel@tonic-gate else if (bp->b_ndev == 0) { 13700Sstevel@tonic-gate dr_op_err(CE_WARN, hp, ESBD_EMPTY_BD, bp->b_path); 13710Sstevel@tonic-gate return; 13720Sstevel@tonic-gate } else { 13730Sstevel@tonic-gate dr_make_comp_nodes(bp); 13740Sstevel@tonic-gate return; 13750Sstevel@tonic-gate } 13760Sstevel@tonic-gate /*NOTREACHED*/ 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate static int 13800Sstevel@tonic-gate dr_disconnect(dr_handle_t *hp) 13810Sstevel@tonic-gate { 13820Sstevel@tonic-gate int i; 13830Sstevel@tonic-gate dr_devset_t devset; 13840Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 13850Sstevel@tonic-gate static fn_t f = "dr_disconnect"; 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate PR_ALL("%s...\n", f); 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate /* 13900Sstevel@tonic-gate * Only devices which are present, but 13910Sstevel@tonic-gate * unattached can be disconnected. 13920Sstevel@tonic-gate */ 13930Sstevel@tonic-gate devset = hp->h_devset & DR_DEVS_PRESENT(bp) & 1394*1772Sjl139090 DR_DEVS_UNATTACHED(bp); 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate if ((devset == 0) && DR_DEVS_PRESENT(bp)) { 13970Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_EMPTY_BD, bp->b_path); 13980Sstevel@tonic-gate return (0); 13990Sstevel@tonic-gate } 14000Sstevel@tonic-gate 14010Sstevel@tonic-gate /* 14020Sstevel@tonic-gate * Block out status during disconnect. 14030Sstevel@tonic-gate */ 14040Sstevel@tonic-gate mutex_enter(&bp->b_slock); 14050Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 14060Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 14070Sstevel@tonic-gate mutex_exit(&bp->b_slock); 14080Sstevel@tonic-gate return (EINTR); 14090Sstevel@tonic-gate } 14100Sstevel@tonic-gate } 14110Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 14120Sstevel@tonic-gate mutex_exit(&bp->b_slock); 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate hp->h_err = drmach_board_disconnect(bp->b_id, &hp->h_opts); 14150Sstevel@tonic-gate 14160Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, devset); 14170Sstevel@tonic-gate 14180Sstevel@tonic-gate ASSERT((DR_DEVS_ATTACHED(bp) & devset) == 0); 14190Sstevel@tonic-gate 14200Sstevel@tonic-gate /* 14210Sstevel@tonic-gate * Update per-device state transitions. 14220Sstevel@tonic-gate */ 14230Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 14240Sstevel@tonic-gate dr_cpu_unit_t *cp; 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_CPU, i)) 14270Sstevel@tonic-gate continue; 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 14300Sstevel@tonic-gate if (dr_disconnect_cpu(cp) == 0) 14310Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY); 14320Sstevel@tonic-gate else if (cp->sbc_cm.sbdev_error != NULL) 14330Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &cp->sbc_cm.sbdev_error); 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate ASSERT(cp->sbc_cm.sbdev_error == NULL); 14360Sstevel@tonic-gate } 14370Sstevel@tonic-gate 14380Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 14390Sstevel@tonic-gate dr_mem_unit_t *mp; 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_MEM, i)) 14420Sstevel@tonic-gate continue; 14430Sstevel@tonic-gate 14440Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 14450Sstevel@tonic-gate if (dr_disconnect_mem(mp) == 0) 14460Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY); 14470Sstevel@tonic-gate else if (mp->sbm_cm.sbdev_error != NULL) 14480Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &mp->sbm_cm.sbdev_error); 14490Sstevel@tonic-gate 14500Sstevel@tonic-gate ASSERT(mp->sbm_cm.sbdev_error == NULL); 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 14540Sstevel@tonic-gate dr_io_unit_t *ip; 14550Sstevel@tonic-gate 14560Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_IO, i)) 14570Sstevel@tonic-gate continue; 14580Sstevel@tonic-gate 14590Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 14600Sstevel@tonic-gate if (dr_disconnect_io(ip) == 0) 14610Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY); 14620Sstevel@tonic-gate else if (ip->sbi_cm.sbdev_error != NULL) 14630Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &ip->sbi_cm.sbdev_error); 14640Sstevel@tonic-gate 14650Sstevel@tonic-gate ASSERT(ip->sbi_cm.sbdev_error == NULL); 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate if (hp->h_err) { 14680Sstevel@tonic-gate /* 14690Sstevel@tonic-gate * For certain errors, drmach_board_disconnect will mark 14700Sstevel@tonic-gate * the board as unusable; in these cases the devtree must 14710Sstevel@tonic-gate * be purged so that status calls will succeed. 14720Sstevel@tonic-gate * XXX 14730Sstevel@tonic-gate * This implementation checks for discrete error codes - 14740Sstevel@tonic-gate * someday, the i/f to drmach_board_disconnect should be 14750Sstevel@tonic-gate * changed to avoid the e_code testing. 14760Sstevel@tonic-gate */ 14770Sstevel@tonic-gate if ((hp->h_err->e_code == ESTC_MBXRPLY) || 14780Sstevel@tonic-gate (hp->h_err->e_code == ESTC_MBXRQST) || 14790Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_UNRECOVERABLE) || 14800Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_RECOVERABLE) || 14810Sstevel@tonic-gate (hp->h_err->e_code == ESTC_DEPROBE)) { 14820Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 14830Sstevel@tonic-gate bp->b_busy = 0; 14840Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 14850Sstevel@tonic-gate 14860Sstevel@tonic-gate if (drmach_board_deprobe(bp->b_id)) 14870Sstevel@tonic-gate goto disconnect_done; 14880Sstevel@tonic-gate else 14890Sstevel@tonic-gate bp->b_ndev = 0; 14900Sstevel@tonic-gate } 14910Sstevel@tonic-gate 14920Sstevel@tonic-gate /* 14930Sstevel@tonic-gate * If the disconnect failed in a recoverable way, 14940Sstevel@tonic-gate * more work is required. 14950Sstevel@tonic-gate * XXX 14960Sstevel@tonic-gate * This implementation checks for discrete error codes - 14970Sstevel@tonic-gate * someday, the i/f to drmach_board_disconnect should be 14980Sstevel@tonic-gate * changed to avoid the e_code testing. 14990Sstevel@tonic-gate */ 15000Sstevel@tonic-gate if ((hp->h_err->e_code == ESTC_MBXRQST) || 15010Sstevel@tonic-gate (hp->h_err->e_code == ESTC_SMS_ERR_RECOVERABLE) || 15020Sstevel@tonic-gate (hp->h_err->e_code == ESTC_DEPROBE)) { 15030Sstevel@tonic-gate /* 15040Sstevel@tonic-gate * With this failure, the board has been deprobed 15050Sstevel@tonic-gate * by IKP, and reprobed. We've already gotten rid 15060Sstevel@tonic-gate * of the old devtree, now we need to reconstruct it 15070Sstevel@tonic-gate * based on the new IKP probe 15080Sstevel@tonic-gate */ 15090Sstevel@tonic-gate if (dr_init_devlists(bp) || (bp->b_ndev == 0)) 15100Sstevel@tonic-gate goto disconnect_done; 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate dr_make_comp_nodes(bp); 15130Sstevel@tonic-gate } 15140Sstevel@tonic-gate } 15150Sstevel@tonic-gate /* 15160Sstevel@tonic-gate * Once all the components on a board have been disconnect 15170Sstevel@tonic-gate * the board's state can transition to disconnected and 15180Sstevel@tonic-gate * we can allow the deprobe to take place. 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate if (hp->h_err == NULL && DR_DEVS_PRESENT(bp) == 0) { 15210Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_OCCUPIED); 15220Sstevel@tonic-gate bp->b_rstate = SBD_STAT_DISCONNECTED; 15230Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 15240Sstevel@tonic-gate bp->b_busy = 0; 15250Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 15260Sstevel@tonic-gate 15270Sstevel@tonic-gate hp->h_err = drmach_board_deprobe(bp->b_id); 15280Sstevel@tonic-gate 15290Sstevel@tonic-gate if (hp->h_err == NULL) { 15300Sstevel@tonic-gate bp->b_ndev = 0; 15310Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 15320Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 15330Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 15340Sstevel@tonic-gate } 15350Sstevel@tonic-gate } 15360Sstevel@tonic-gate 15370Sstevel@tonic-gate disconnect_done: 15380Sstevel@tonic-gate dr_unlock_status(bp); 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate return (0); 15410Sstevel@tonic-gate } 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate /* 15440Sstevel@tonic-gate * Check if a particular device is a valid target of the current 15450Sstevel@tonic-gate * operation. Return 1 if it is a valid target, and 0 otherwise. 15460Sstevel@tonic-gate */ 15470Sstevel@tonic-gate static int 15480Sstevel@tonic-gate dr_dev_is_target(dr_dev_unit_t *dp, int present_only, uint_t uset) 15490Sstevel@tonic-gate { 15500Sstevel@tonic-gate dr_common_unit_t *cp; 15510Sstevel@tonic-gate int is_present; 15520Sstevel@tonic-gate int is_attached; 15530Sstevel@tonic-gate 15540Sstevel@tonic-gate cp = &dp->du_common; 15550Sstevel@tonic-gate 15560Sstevel@tonic-gate /* check if the user requested this device */ 15570Sstevel@tonic-gate if ((uset & (1 << cp->sbdev_unum)) == 0) { 15580Sstevel@tonic-gate return (0); 15590Sstevel@tonic-gate } 15600Sstevel@tonic-gate 15610Sstevel@tonic-gate is_present = DR_DEV_IS_PRESENT(cp) ? 1 : 0; 15620Sstevel@tonic-gate is_attached = DR_DEV_IS_ATTACHED(cp) ? 1 : 0; 15630Sstevel@tonic-gate 15640Sstevel@tonic-gate /* 15650Sstevel@tonic-gate * If the present_only flag is set, a valid target 15660Sstevel@tonic-gate * must be present but not attached. Otherwise, it 15670Sstevel@tonic-gate * must be both present and attached. 15680Sstevel@tonic-gate */ 15690Sstevel@tonic-gate if (is_present && (present_only ^ is_attached)) { 15700Sstevel@tonic-gate /* sanity check */ 15710Sstevel@tonic-gate ASSERT(cp->sbdev_id != (drmachid_t)0); 15720Sstevel@tonic-gate 15730Sstevel@tonic-gate return (1); 15740Sstevel@tonic-gate } 15750Sstevel@tonic-gate 15760Sstevel@tonic-gate return (0); 15770Sstevel@tonic-gate } 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate static void 15800Sstevel@tonic-gate dr_dev_make_list(dr_handle_t *hp, sbd_comp_type_t type, int present_only, 15810Sstevel@tonic-gate dr_common_unit_t ***devlist, int *devnum) 15820Sstevel@tonic-gate { 15830Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 15840Sstevel@tonic-gate int unum; 15850Sstevel@tonic-gate int nunits; 15860Sstevel@tonic-gate uint_t uset; 15870Sstevel@tonic-gate int len; 15880Sstevel@tonic-gate dr_common_unit_t **list, **wp; 15890Sstevel@tonic-gate 15900Sstevel@tonic-gate switch (type) { 15910Sstevel@tonic-gate case SBD_COMP_CPU: 15920Sstevel@tonic-gate nunits = MAX_CPU_UNITS_PER_BOARD; 15930Sstevel@tonic-gate break; 15940Sstevel@tonic-gate case SBD_COMP_MEM: 15950Sstevel@tonic-gate nunits = MAX_MEM_UNITS_PER_BOARD; 15960Sstevel@tonic-gate break; 15970Sstevel@tonic-gate case SBD_COMP_IO: 15980Sstevel@tonic-gate nunits = MAX_IO_UNITS_PER_BOARD; 15990Sstevel@tonic-gate break; 16000Sstevel@tonic-gate default: 16010Sstevel@tonic-gate /* catch this in debug kernels */ 16020Sstevel@tonic-gate ASSERT(0); 16030Sstevel@tonic-gate break; 16040Sstevel@tonic-gate } 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate /* allocate list storage. */ 16070Sstevel@tonic-gate len = sizeof (dr_common_unit_t *) * (nunits + 1); 16080Sstevel@tonic-gate list = kmem_zalloc(len, KM_SLEEP); 16090Sstevel@tonic-gate 16100Sstevel@tonic-gate /* record length of storage in first element */ 1611930Smathue *list++ = (dr_common_unit_t *)(uintptr_t)len; 16120Sstevel@tonic-gate 16130Sstevel@tonic-gate /* get bit array signifying which units are to be involved */ 16140Sstevel@tonic-gate uset = DEVSET_GET_UNITSET(hp->h_devset, type); 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate /* 16170Sstevel@tonic-gate * Adjust the loop count for CPU devices since all cores 16180Sstevel@tonic-gate * in a CMP will be examined in a single iteration. 16190Sstevel@tonic-gate */ 16200Sstevel@tonic-gate if (type == SBD_COMP_CPU) { 16210Sstevel@tonic-gate nunits = MAX_CMP_UNITS_PER_BOARD; 16220Sstevel@tonic-gate } 16230Sstevel@tonic-gate 16240Sstevel@tonic-gate /* populate list */ 16250Sstevel@tonic-gate for (wp = list, unum = 0; unum < nunits; unum++) { 16260Sstevel@tonic-gate 16270Sstevel@tonic-gate dr_dev_unit_t *dp; 16280Sstevel@tonic-gate int core; 16290Sstevel@tonic-gate int cunum; 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, type, unum); 16320Sstevel@tonic-gate if (dr_dev_is_target(dp, present_only, uset)) { 16330Sstevel@tonic-gate *wp++ = &dp->du_common; 16340Sstevel@tonic-gate } 16350Sstevel@tonic-gate 16360Sstevel@tonic-gate /* further processing is only required for CPUs */ 16370Sstevel@tonic-gate if (type != SBD_COMP_CPU) { 16380Sstevel@tonic-gate continue; 16390Sstevel@tonic-gate } 16400Sstevel@tonic-gate 16410Sstevel@tonic-gate /* 16420Sstevel@tonic-gate * Add any additional cores from the current CPU 16430Sstevel@tonic-gate * device. This is to ensure that all the cores 16440Sstevel@tonic-gate * are grouped together in the device list, and 16450Sstevel@tonic-gate * consequently sequenced together during the actual 16460Sstevel@tonic-gate * operation. 16470Sstevel@tonic-gate */ 16480Sstevel@tonic-gate for (core = 1; core < MAX_CORES_PER_CMP; core++) { 16490Sstevel@tonic-gate 16500Sstevel@tonic-gate cunum = DR_CMP_CORE_UNUM(unum, core); 16510Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, type, cunum); 16520Sstevel@tonic-gate 16530Sstevel@tonic-gate if (dr_dev_is_target(dp, present_only, uset)) { 16540Sstevel@tonic-gate *wp++ = &dp->du_common; 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate } 16570Sstevel@tonic-gate } 16580Sstevel@tonic-gate 16590Sstevel@tonic-gate /* calculate number of units in list, return result and list pointer */ 16600Sstevel@tonic-gate *devnum = wp - list; 16610Sstevel@tonic-gate *devlist = list; 16620Sstevel@tonic-gate } 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate static void 16650Sstevel@tonic-gate dr_dev_clean_up(dr_handle_t *hp, dr_common_unit_t **list, int devnum) 16660Sstevel@tonic-gate { 16670Sstevel@tonic-gate int len; 16680Sstevel@tonic-gate int n = 0; 16690Sstevel@tonic-gate dr_common_unit_t *cp, **rp = list; 16700Sstevel@tonic-gate 16710Sstevel@tonic-gate /* 16720Sstevel@tonic-gate * move first encountered unit error to handle if handle 16730Sstevel@tonic-gate * does not yet have a recorded error. 16740Sstevel@tonic-gate */ 16750Sstevel@tonic-gate if (hp->h_err == NULL) { 16760Sstevel@tonic-gate while (n++ < devnum) { 16770Sstevel@tonic-gate cp = *rp++; 16780Sstevel@tonic-gate if (cp->sbdev_error != NULL) { 16790Sstevel@tonic-gate hp->h_err = cp->sbdev_error; 16800Sstevel@tonic-gate cp->sbdev_error = NULL; 16810Sstevel@tonic-gate break; 16820Sstevel@tonic-gate } 16830Sstevel@tonic-gate } 16840Sstevel@tonic-gate } 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate /* free remaining unit errors */ 16870Sstevel@tonic-gate while (n++ < devnum) { 16880Sstevel@tonic-gate cp = *rp++; 16890Sstevel@tonic-gate if (cp->sbdev_error != NULL) { 16900Sstevel@tonic-gate sbd_err_clear(&cp->sbdev_error); 16910Sstevel@tonic-gate cp->sbdev_error = NULL; 16920Sstevel@tonic-gate } 16930Sstevel@tonic-gate } 16940Sstevel@tonic-gate 16950Sstevel@tonic-gate /* free list */ 16960Sstevel@tonic-gate list -= 1; 1697930Smathue len = (int)(uintptr_t)list[0]; 16980Sstevel@tonic-gate kmem_free(list, len); 16990Sstevel@tonic-gate } 17000Sstevel@tonic-gate 17010Sstevel@tonic-gate static int 17020Sstevel@tonic-gate dr_dev_walk(dr_handle_t *hp, sbd_comp_type_t type, int present_only, 17030Sstevel@tonic-gate int (*pre_op)(dr_handle_t *, dr_common_unit_t **, int), 17040Sstevel@tonic-gate void (*op)(dr_handle_t *, dr_common_unit_t *), 17050Sstevel@tonic-gate int (*post_op)(dr_handle_t *, dr_common_unit_t **, int), 17060Sstevel@tonic-gate void (*board_op)(dr_handle_t *, dr_common_unit_t **, int)) 17070Sstevel@tonic-gate { 17080Sstevel@tonic-gate int devnum, rv; 17090Sstevel@tonic-gate dr_common_unit_t **devlist; 17100Sstevel@tonic-gate 17110Sstevel@tonic-gate dr_dev_make_list(hp, type, present_only, &devlist, &devnum); 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate rv = 0; 17140Sstevel@tonic-gate if (devnum > 0) { 17150Sstevel@tonic-gate rv = (*pre_op)(hp, devlist, devnum); 17160Sstevel@tonic-gate if (rv == 0) { 17170Sstevel@tonic-gate int n; 17180Sstevel@tonic-gate 17190Sstevel@tonic-gate for (n = 0; n < devnum; n++) 17200Sstevel@tonic-gate (*op)(hp, devlist[n]); 17210Sstevel@tonic-gate 17220Sstevel@tonic-gate rv = (*post_op)(hp, devlist, devnum); 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate (*board_op)(hp, devlist, devnum); 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate } 17270Sstevel@tonic-gate 17280Sstevel@tonic-gate dr_dev_clean_up(hp, devlist, devnum); 17290Sstevel@tonic-gate return (rv); 17300Sstevel@tonic-gate } 17310Sstevel@tonic-gate 17320Sstevel@tonic-gate /*ARGSUSED*/ 17330Sstevel@tonic-gate static int 17340Sstevel@tonic-gate dr_dev_noop(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum) 17350Sstevel@tonic-gate { 17360Sstevel@tonic-gate return (0); 17370Sstevel@tonic-gate } 17380Sstevel@tonic-gate 17390Sstevel@tonic-gate static void 17400Sstevel@tonic-gate dr_attach_update_state(dr_handle_t *hp, 17410Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 17420Sstevel@tonic-gate { 17430Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 17440Sstevel@tonic-gate int i; 17450Sstevel@tonic-gate dr_devset_t devs_unattached, devs_present; 17460Sstevel@tonic-gate static fn_t f = "dr_post_attach_devlist"; 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate for (i = 0; i < devnum; i++) { 17490Sstevel@tonic-gate dr_common_unit_t *cp = devlist[i]; 17500Sstevel@tonic-gate 17510Sstevel@tonic-gate if (dr_check_unit_attached(cp) == -1) { 17520Sstevel@tonic-gate PR_ALL("%s: ERROR %s not attached\n", 17530Sstevel@tonic-gate f, cp->sbdev_path); 17540Sstevel@tonic-gate continue; 17550Sstevel@tonic-gate } 17560Sstevel@tonic-gate 17570Sstevel@tonic-gate DR_DEV_SET_ATTACHED(cp); 17580Sstevel@tonic-gate 17590Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_CONFIGURED); 17600Sstevel@tonic-gate cp->sbdev_cond = SBD_COND_OK; 17610Sstevel@tonic-gate } 17620Sstevel@tonic-gate 17630Sstevel@tonic-gate devs_present = DR_DEVS_PRESENT(bp); 17640Sstevel@tonic-gate devs_unattached = DR_DEVS_UNATTACHED(bp); 17650Sstevel@tonic-gate 17660Sstevel@tonic-gate switch (bp->b_state) { 17670Sstevel@tonic-gate case DR_STATE_CONNECTED: 17680Sstevel@tonic-gate case DR_STATE_UNCONFIGURED: 17690Sstevel@tonic-gate ASSERT(devs_present); 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate if (devs_unattached == 0) { 17720Sstevel@tonic-gate /* 17730Sstevel@tonic-gate * All devices finally attached. 17740Sstevel@tonic-gate */ 17750Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 17760Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 17770Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 17780Sstevel@tonic-gate hp->h_bd->b_cond = SBD_COND_OK; 17790Sstevel@tonic-gate hp->h_bd->b_busy = 0; 17800Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 17810Sstevel@tonic-gate } else if (devs_present != devs_unattached) { 17820Sstevel@tonic-gate /* 17830Sstevel@tonic-gate * Only some devices are fully attached. 17840Sstevel@tonic-gate */ 17850Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 17860Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 17870Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 17880Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 17890Sstevel@tonic-gate } 17900Sstevel@tonic-gate break; 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate case DR_STATE_PARTIAL: 17930Sstevel@tonic-gate ASSERT(devs_present); 17940Sstevel@tonic-gate /* 17950Sstevel@tonic-gate * All devices finally attached. 17960Sstevel@tonic-gate */ 17970Sstevel@tonic-gate if (devs_unattached == 0) { 17980Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 17990Sstevel@tonic-gate hp->h_bd->b_rstate = SBD_STAT_CONNECTED; 18000Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 18010Sstevel@tonic-gate hp->h_bd->b_cond = SBD_COND_OK; 18020Sstevel@tonic-gate hp->h_bd->b_busy = 0; 18030Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 18040Sstevel@tonic-gate } 18050Sstevel@tonic-gate break; 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate default: 18080Sstevel@tonic-gate break; 18090Sstevel@tonic-gate } 18100Sstevel@tonic-gate } 18110Sstevel@tonic-gate 18120Sstevel@tonic-gate static void 18130Sstevel@tonic-gate dr_dev_configure(dr_handle_t *hp) 18140Sstevel@tonic-gate { 18150Sstevel@tonic-gate int rv; 18160Sstevel@tonic-gate 18170Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_CPU, 1, 18180Sstevel@tonic-gate dr_pre_attach_cpu, 18190Sstevel@tonic-gate dr_attach_cpu, 18200Sstevel@tonic-gate dr_post_attach_cpu, 18210Sstevel@tonic-gate dr_attach_update_state); 18220Sstevel@tonic-gate 18230Sstevel@tonic-gate if (rv >= 0) { 18240Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_MEM, 1, 18250Sstevel@tonic-gate dr_pre_attach_mem, 18260Sstevel@tonic-gate dr_attach_mem, 18270Sstevel@tonic-gate dr_post_attach_mem, 18280Sstevel@tonic-gate dr_attach_update_state); 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate if (rv >= 0) { 18320Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_IO, 1, 18330Sstevel@tonic-gate dr_pre_attach_io, 18340Sstevel@tonic-gate dr_attach_io, 18350Sstevel@tonic-gate dr_post_attach_io, 18360Sstevel@tonic-gate dr_attach_update_state); 18370Sstevel@tonic-gate } 18380Sstevel@tonic-gate } 18390Sstevel@tonic-gate 18400Sstevel@tonic-gate static void 18410Sstevel@tonic-gate dr_release_update_state(dr_handle_t *hp, 18420Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 18430Sstevel@tonic-gate { 18440Sstevel@tonic-gate _NOTE(ARGUNUSED(devlist)) 18450Sstevel@tonic-gate _NOTE(ARGUNUSED(devnum)) 18460Sstevel@tonic-gate 18470Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate /* 18500Sstevel@tonic-gate * If the entire board was released and all components 18510Sstevel@tonic-gate * unreferenced then transfer it to the UNREFERENCED state. 18520Sstevel@tonic-gate */ 18530Sstevel@tonic-gate if ((bp->b_state != DR_STATE_RELEASE) && 18540Sstevel@tonic-gate (DR_DEVS_RELEASED(bp) == DR_DEVS_ATTACHED(bp))) { 18550Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_RELEASE); 18560Sstevel@tonic-gate hp->h_bd->b_busy = 1; 18570Sstevel@tonic-gate } 18580Sstevel@tonic-gate } 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate /* called by dr_release_done [below] and dr_release_mem_done [dr_mem.c] */ 18610Sstevel@tonic-gate int 18620Sstevel@tonic-gate dr_release_dev_done(dr_common_unit_t *cp) 18630Sstevel@tonic-gate { 18640Sstevel@tonic-gate if (cp->sbdev_state == DR_STATE_RELEASE) { 18650Sstevel@tonic-gate ASSERT(DR_DEV_IS_RELEASED(cp)); 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate DR_DEV_SET_UNREFERENCED(cp); 18680Sstevel@tonic-gate 18690Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_UNREFERENCED); 18700Sstevel@tonic-gate 18710Sstevel@tonic-gate return (0); 18720Sstevel@tonic-gate } else { 18730Sstevel@tonic-gate return (-1); 18740Sstevel@tonic-gate } 18750Sstevel@tonic-gate } 18760Sstevel@tonic-gate 18770Sstevel@tonic-gate static void 18780Sstevel@tonic-gate dr_release_done(dr_handle_t *hp, dr_common_unit_t *cp) 18790Sstevel@tonic-gate { 18800Sstevel@tonic-gate _NOTE(ARGUNUSED(hp)) 18810Sstevel@tonic-gate 18820Sstevel@tonic-gate dr_board_t *bp; 18830Sstevel@tonic-gate static fn_t f = "dr_release_done"; 18840Sstevel@tonic-gate 18850Sstevel@tonic-gate PR_ALL("%s...\n", f); 18860Sstevel@tonic-gate 18870Sstevel@tonic-gate /* get board pointer & sanity check */ 18880Sstevel@tonic-gate bp = cp->sbdev_bp; 18890Sstevel@tonic-gate ASSERT(bp == hp->h_bd); 18900Sstevel@tonic-gate 18910Sstevel@tonic-gate /* 18920Sstevel@tonic-gate * Transfer the device which just completed its release 18930Sstevel@tonic-gate * to the UNREFERENCED state. 18940Sstevel@tonic-gate */ 18950Sstevel@tonic-gate switch (cp->sbdev_type) { 18960Sstevel@tonic-gate case SBD_COMP_MEM: 18970Sstevel@tonic-gate dr_release_mem_done(cp); 18980Sstevel@tonic-gate break; 18990Sstevel@tonic-gate 19000Sstevel@tonic-gate default: 19010Sstevel@tonic-gate DR_DEV_SET_RELEASED(cp); 19020Sstevel@tonic-gate 19030Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_RELEASE); 19040Sstevel@tonic-gate 19050Sstevel@tonic-gate (void) dr_release_dev_done(cp); 19060Sstevel@tonic-gate break; 19070Sstevel@tonic-gate } 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate /* 19100Sstevel@tonic-gate * If we're not already in the RELEASE state for this 19110Sstevel@tonic-gate * board and we now have released all that were previously 19120Sstevel@tonic-gate * attached, then transfer the board to the RELEASE state. 19130Sstevel@tonic-gate */ 19140Sstevel@tonic-gate if ((bp->b_state == DR_STATE_RELEASE) && 19150Sstevel@tonic-gate (DR_DEVS_RELEASED(bp) == DR_DEVS_UNREFERENCED(bp))) { 19160Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_UNREFERENCED); 19170Sstevel@tonic-gate bp->b_busy = 1; 19180Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 19190Sstevel@tonic-gate } 19200Sstevel@tonic-gate } 19210Sstevel@tonic-gate 19220Sstevel@tonic-gate static void 19230Sstevel@tonic-gate dr_dev_release_mem(dr_handle_t *hp, dr_common_unit_t *dv) 19240Sstevel@tonic-gate { 19250Sstevel@tonic-gate dr_release_mem(dv); 19260Sstevel@tonic-gate dr_release_done(hp, dv); 19270Sstevel@tonic-gate } 19280Sstevel@tonic-gate 19290Sstevel@tonic-gate static void 19300Sstevel@tonic-gate dr_dev_release(dr_handle_t *hp) 19310Sstevel@tonic-gate { 19320Sstevel@tonic-gate int rv; 19330Sstevel@tonic-gate 19340Sstevel@tonic-gate hp->h_bd->b_busy = 1; 19350Sstevel@tonic-gate 19360Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_CPU, 0, 19370Sstevel@tonic-gate dr_pre_release_cpu, 19380Sstevel@tonic-gate dr_release_done, 19390Sstevel@tonic-gate dr_dev_noop, 19400Sstevel@tonic-gate dr_release_update_state); 19410Sstevel@tonic-gate 19420Sstevel@tonic-gate if (rv >= 0) { 19430Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_MEM, 0, 19440Sstevel@tonic-gate dr_pre_release_mem, 19450Sstevel@tonic-gate dr_dev_release_mem, 19460Sstevel@tonic-gate dr_dev_noop, 19470Sstevel@tonic-gate dr_release_update_state); 19480Sstevel@tonic-gate } 19490Sstevel@tonic-gate 19500Sstevel@tonic-gate if (rv >= 0) { 19510Sstevel@tonic-gate rv = dr_dev_walk(hp, SBD_COMP_IO, 0, 19520Sstevel@tonic-gate dr_pre_release_io, 19530Sstevel@tonic-gate dr_release_done, 19540Sstevel@tonic-gate dr_dev_noop, 19550Sstevel@tonic-gate dr_release_update_state); 19560Sstevel@tonic-gate 19570Sstevel@tonic-gate } 19580Sstevel@tonic-gate 19590Sstevel@tonic-gate if (rv < 0) 19600Sstevel@tonic-gate hp->h_bd->b_busy = 0; 19610Sstevel@tonic-gate /* else, b_busy will be cleared in dr_detach_update_state() */ 19620Sstevel@tonic-gate } 19630Sstevel@tonic-gate 19640Sstevel@tonic-gate static void 19650Sstevel@tonic-gate dr_detach_update_state(dr_handle_t *hp, 19660Sstevel@tonic-gate dr_common_unit_t **devlist, int devnum) 19670Sstevel@tonic-gate { 19680Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 19690Sstevel@tonic-gate int i; 19700Sstevel@tonic-gate dr_state_t bstate; 19710Sstevel@tonic-gate static fn_t f = "dr_detach_update_state"; 19720Sstevel@tonic-gate 19730Sstevel@tonic-gate for (i = 0; i < devnum; i++) { 19740Sstevel@tonic-gate dr_common_unit_t *cp = devlist[i]; 19750Sstevel@tonic-gate 19760Sstevel@tonic-gate if (dr_check_unit_attached(cp) >= 0) { 19770Sstevel@tonic-gate /* 19780Sstevel@tonic-gate * Device is still attached probably due 19790Sstevel@tonic-gate * to an error. Need to keep track of it. 19800Sstevel@tonic-gate */ 19810Sstevel@tonic-gate PR_ALL("%s: ERROR %s not detached\n", 19820Sstevel@tonic-gate f, cp->sbdev_path); 19830Sstevel@tonic-gate 19840Sstevel@tonic-gate continue; 19850Sstevel@tonic-gate } 19860Sstevel@tonic-gate 19870Sstevel@tonic-gate DR_DEV_CLR_ATTACHED(cp); 19880Sstevel@tonic-gate DR_DEV_CLR_RELEASED(cp); 19890Sstevel@tonic-gate DR_DEV_CLR_UNREFERENCED(cp); 19900Sstevel@tonic-gate dr_device_transition(cp, DR_STATE_UNCONFIGURED); 19910Sstevel@tonic-gate } 19920Sstevel@tonic-gate 19930Sstevel@tonic-gate bstate = bp->b_state; 19940Sstevel@tonic-gate if (bstate != DR_STATE_UNCONFIGURED) { 19950Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp) == DR_DEVS_UNATTACHED(bp)) { 19960Sstevel@tonic-gate /* 19970Sstevel@tonic-gate * All devices are finally detached. 19980Sstevel@tonic-gate */ 19990Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_UNCONFIGURED); 20000Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_UNCONFIGURED; 20010Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 20020Sstevel@tonic-gate } else if ((bp->b_state != DR_STATE_PARTIAL) && 2003*1772Sjl139090 (DR_DEVS_ATTACHED(bp) != 2004*1772Sjl139090 DR_DEVS_PRESENT(bp))) { 20050Sstevel@tonic-gate /* 20060Sstevel@tonic-gate * Some devices remain attached. 20070Sstevel@tonic-gate */ 20080Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 20090Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate 20120Sstevel@tonic-gate if ((hp->h_devset & DR_DEVS_UNATTACHED(bp)) == hp->h_devset) 20130Sstevel@tonic-gate hp->h_bd->b_busy = 0; 20140Sstevel@tonic-gate } 20150Sstevel@tonic-gate } 20160Sstevel@tonic-gate 20170Sstevel@tonic-gate static int 20180Sstevel@tonic-gate dr_dev_unconfigure(dr_handle_t *hp) 20190Sstevel@tonic-gate { 20200Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 20210Sstevel@tonic-gate 20220Sstevel@tonic-gate /* 20230Sstevel@tonic-gate * Block out status during IO unconfig. 20240Sstevel@tonic-gate */ 20250Sstevel@tonic-gate mutex_enter(&bp->b_slock); 20260Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 20270Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 20280Sstevel@tonic-gate mutex_exit(&bp->b_slock); 20290Sstevel@tonic-gate return (EINTR); 20300Sstevel@tonic-gate } 20310Sstevel@tonic-gate } 20320Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 20330Sstevel@tonic-gate mutex_exit(&bp->b_slock); 20340Sstevel@tonic-gate 20350Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_IO, 0, 20360Sstevel@tonic-gate dr_pre_detach_io, 20370Sstevel@tonic-gate dr_detach_io, 20380Sstevel@tonic-gate dr_post_detach_io, 20390Sstevel@tonic-gate dr_detach_update_state); 20400Sstevel@tonic-gate 20410Sstevel@tonic-gate dr_unlock_status(bp); 20420Sstevel@tonic-gate 20430Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_CPU, 0, 20440Sstevel@tonic-gate dr_pre_detach_cpu, 20450Sstevel@tonic-gate dr_detach_cpu, 20460Sstevel@tonic-gate dr_post_detach_cpu, 20470Sstevel@tonic-gate dr_detach_update_state); 20480Sstevel@tonic-gate 20490Sstevel@tonic-gate (void) dr_dev_walk(hp, SBD_COMP_MEM, 0, 20500Sstevel@tonic-gate dr_pre_detach_mem, 20510Sstevel@tonic-gate dr_detach_mem, 20520Sstevel@tonic-gate dr_post_detach_mem, 20530Sstevel@tonic-gate dr_detach_update_state); 20540Sstevel@tonic-gate 20550Sstevel@tonic-gate return (0); 20560Sstevel@tonic-gate } 20570Sstevel@tonic-gate 20580Sstevel@tonic-gate static void 20590Sstevel@tonic-gate dr_dev_cancel(dr_handle_t *hp) 20600Sstevel@tonic-gate { 20610Sstevel@tonic-gate int i; 20620Sstevel@tonic-gate dr_devset_t devset; 20630Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 20640Sstevel@tonic-gate static fn_t f = "dr_dev_cancel"; 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate PR_ALL("%s...\n", f); 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate /* 20690Sstevel@tonic-gate * Only devices which have been "released" are 20700Sstevel@tonic-gate * subject to cancellation. 20710Sstevel@tonic-gate */ 20720Sstevel@tonic-gate devset = hp->h_devset & DR_DEVS_RELEASED(bp); 20730Sstevel@tonic-gate 20740Sstevel@tonic-gate /* 20750Sstevel@tonic-gate * Nothing to do for CPUs or IO other than change back 20760Sstevel@tonic-gate * their state. 20770Sstevel@tonic-gate */ 20780Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 20790Sstevel@tonic-gate dr_cpu_unit_t *cp; 20800Sstevel@tonic-gate dr_state_t nstate; 20810Sstevel@tonic-gate 20820Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_CPU, i)) 20830Sstevel@tonic-gate continue; 20840Sstevel@tonic-gate 20850Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 20860Sstevel@tonic-gate if (dr_cancel_cpu(cp) == 0) 20870Sstevel@tonic-gate nstate = DR_STATE_CONFIGURED; 20880Sstevel@tonic-gate else 20890Sstevel@tonic-gate nstate = DR_STATE_FATAL; 20900Sstevel@tonic-gate 20910Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, nstate); 20920Sstevel@tonic-gate } 20930Sstevel@tonic-gate 20940Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 20950Sstevel@tonic-gate dr_io_unit_t *ip; 20960Sstevel@tonic-gate 20970Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_IO, i)) 20980Sstevel@tonic-gate continue; 20990Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 21000Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_CONFIGURED); 21010Sstevel@tonic-gate } 21020Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 21030Sstevel@tonic-gate dr_mem_unit_t *mp; 21040Sstevel@tonic-gate dr_state_t nstate; 21050Sstevel@tonic-gate 21060Sstevel@tonic-gate if (!DEVSET_IN_SET(devset, SBD_COMP_MEM, i)) 21070Sstevel@tonic-gate continue; 21080Sstevel@tonic-gate 21090Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 21100Sstevel@tonic-gate if (dr_cancel_mem(mp) == 0) 21110Sstevel@tonic-gate nstate = DR_STATE_CONFIGURED; 21120Sstevel@tonic-gate else 21130Sstevel@tonic-gate nstate = DR_STATE_FATAL; 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, nstate); 21160Sstevel@tonic-gate } 21170Sstevel@tonic-gate 21180Sstevel@tonic-gate PR_ALL("%s: unreleasing devset (0x%x)\n", f, (uint_t)devset); 21190Sstevel@tonic-gate 21200Sstevel@tonic-gate DR_DEVS_CANCEL(bp, devset); 21210Sstevel@tonic-gate 21220Sstevel@tonic-gate if (DR_DEVS_RELEASED(bp) == 0) { 21230Sstevel@tonic-gate dr_state_t new_state; 21240Sstevel@tonic-gate /* 21250Sstevel@tonic-gate * If the board no longer has any released devices 21260Sstevel@tonic-gate * than transfer it back to the CONFIG/PARTIAL state. 21270Sstevel@tonic-gate */ 21280Sstevel@tonic-gate if (DR_DEVS_ATTACHED(bp) == DR_DEVS_PRESENT(bp)) 21290Sstevel@tonic-gate new_state = DR_STATE_CONFIGURED; 21300Sstevel@tonic-gate else 21310Sstevel@tonic-gate new_state = DR_STATE_PARTIAL; 21320Sstevel@tonic-gate if (bp->b_state != new_state) { 21330Sstevel@tonic-gate dr_board_transition(bp, new_state); 21340Sstevel@tonic-gate } 21350Sstevel@tonic-gate hp->h_bd->b_ostate = SBD_STAT_CONFIGURED; 21360Sstevel@tonic-gate hp->h_bd->b_busy = 0; 21370Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time); 21380Sstevel@tonic-gate } 21390Sstevel@tonic-gate } 21400Sstevel@tonic-gate 21410Sstevel@tonic-gate static int 21420Sstevel@tonic-gate dr_dev_status(dr_handle_t *hp) 21430Sstevel@tonic-gate { 21440Sstevel@tonic-gate int nstat, mode, ncm, sz, pbsz, pnstat; 21450Sstevel@tonic-gate dr_handle_t *shp; 21460Sstevel@tonic-gate dr_devset_t devset = 0; 21470Sstevel@tonic-gate sbd_stat_t *dstatp = NULL; 21480Sstevel@tonic-gate sbd_dev_stat_t *devstatp; 21490Sstevel@tonic-gate dr_board_t *bp; 21500Sstevel@tonic-gate drmach_status_t pstat; 21510Sstevel@tonic-gate int rv = 0; 21520Sstevel@tonic-gate 21530Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 21540Sstevel@tonic-gate int sz32 = 0; 21550Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 21560Sstevel@tonic-gate 21570Sstevel@tonic-gate static fn_t f = "dr_status"; 21580Sstevel@tonic-gate 21590Sstevel@tonic-gate PR_ALL("%s...\n", f); 21600Sstevel@tonic-gate 21610Sstevel@tonic-gate mode = hp->h_mode; 21620Sstevel@tonic-gate shp = hp; 21630Sstevel@tonic-gate devset = shp->h_devset; 21640Sstevel@tonic-gate bp = hp->h_bd; 21650Sstevel@tonic-gate 21660Sstevel@tonic-gate /* 21670Sstevel@tonic-gate * Block out disconnect, unassign, IO unconfigure and 21680Sstevel@tonic-gate * devinfo branch creation during status. 21690Sstevel@tonic-gate */ 21700Sstevel@tonic-gate mutex_enter(&bp->b_slock); 21710Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) { 21720Sstevel@tonic-gate if (cv_wait_sig(&bp->b_scv, &bp->b_slock) == 0) { 21730Sstevel@tonic-gate mutex_exit(&bp->b_slock); 21740Sstevel@tonic-gate return (EINTR); 21750Sstevel@tonic-gate } 21760Sstevel@tonic-gate } 21770Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 21780Sstevel@tonic-gate mutex_exit(&bp->b_slock); 21790Sstevel@tonic-gate 21800Sstevel@tonic-gate ncm = 1; 21810Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_type == SBD_COMP_NONE) { 21820Sstevel@tonic-gate if (dr_cmd_flags(hp) & SBD_FLAG_ALLCMP) { 21830Sstevel@tonic-gate /* 21840Sstevel@tonic-gate * Calculate the maximum number of components possible 21850Sstevel@tonic-gate * for a board. This number will be used to size the 21860Sstevel@tonic-gate * status scratch buffer used by board and component 21870Sstevel@tonic-gate * status functions. 21880Sstevel@tonic-gate * This buffer may differ in size from what is provided 21890Sstevel@tonic-gate * by the plugin, since the known component set on the 21900Sstevel@tonic-gate * board may change between the plugin's GETNCM call, and 21910Sstevel@tonic-gate * the status call. Sizing will be adjusted to the plugin's 21920Sstevel@tonic-gate * receptacle buffer at copyout time. 21930Sstevel@tonic-gate */ 21940Sstevel@tonic-gate ncm = MAX_CPU_UNITS_PER_BOARD + 21950Sstevel@tonic-gate MAX_MEM_UNITS_PER_BOARD + 21960Sstevel@tonic-gate MAX_IO_UNITS_PER_BOARD; 21970Sstevel@tonic-gate 21980Sstevel@tonic-gate } else { 21990Sstevel@tonic-gate /* 22000Sstevel@tonic-gate * In the case of c_type == SBD_COMP_NONE, and 22010Sstevel@tonic-gate * SBD_FLAG_ALLCMP not specified, only the board 22020Sstevel@tonic-gate * info is to be returned, no components. 22030Sstevel@tonic-gate */ 22040Sstevel@tonic-gate ncm = 0; 22050Sstevel@tonic-gate devset = 0; 22060Sstevel@tonic-gate } 22070Sstevel@tonic-gate } 22080Sstevel@tonic-gate 22090Sstevel@tonic-gate sz = sizeof (sbd_stat_t); 22100Sstevel@tonic-gate if (ncm > 1) 22110Sstevel@tonic-gate sz += sizeof (sbd_dev_stat_t) * (ncm - 1); 22120Sstevel@tonic-gate 22130Sstevel@tonic-gate 22140Sstevel@tonic-gate pbsz = (int)hp->h_sbdcmd.cmd_stat.s_nbytes; 22150Sstevel@tonic-gate pnstat = (pbsz - sizeof (sbd_stat_t))/sizeof (sbd_dev_stat_t); 22160Sstevel@tonic-gate 22170Sstevel@tonic-gate /* 22180Sstevel@tonic-gate * s_nbytes describes the size of the preallocated user 22190Sstevel@tonic-gate * buffer into which the application is execting to 22200Sstevel@tonic-gate * receive the sbd_stat_t and sbd_dev_stat_t structures. 22210Sstevel@tonic-gate */ 22220Sstevel@tonic-gate 22230Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 22240Sstevel@tonic-gate 22250Sstevel@tonic-gate /* 22260Sstevel@tonic-gate * More buffer space is required for the 64bit to 32bit 22270Sstevel@tonic-gate * conversion of data structures. 22280Sstevel@tonic-gate */ 22290Sstevel@tonic-gate if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) { 22300Sstevel@tonic-gate sz32 = sizeof (sbd_stat32_t); 22310Sstevel@tonic-gate if (ncm > 1) 22320Sstevel@tonic-gate sz32 += sizeof (sbd_dev_stat32_t) * (ncm - 1); 22330Sstevel@tonic-gate pnstat = (pbsz - sizeof (sbd_stat32_t))/ 2234*1772Sjl139090 sizeof (sbd_dev_stat32_t); 22350Sstevel@tonic-gate } 22360Sstevel@tonic-gate 22370Sstevel@tonic-gate sz += sz32; 22380Sstevel@tonic-gate #endif 22390Sstevel@tonic-gate /* 22400Sstevel@tonic-gate * Since one sbd_dev_stat_t is included in the sbd_stat_t, 22410Sstevel@tonic-gate * increment the plugin's nstat count. 22420Sstevel@tonic-gate */ 22430Sstevel@tonic-gate ++pnstat; 22440Sstevel@tonic-gate 22450Sstevel@tonic-gate if (bp->b_id == 0) { 22460Sstevel@tonic-gate bzero(&pstat, sizeof (pstat)); 22470Sstevel@tonic-gate } else { 22480Sstevel@tonic-gate sbd_error_t *err; 22490Sstevel@tonic-gate 22500Sstevel@tonic-gate err = drmach_status(bp->b_id, &pstat); 22510Sstevel@tonic-gate if (err) { 22520Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &err); 22530Sstevel@tonic-gate rv = EIO; 22540Sstevel@tonic-gate goto status_done; 22550Sstevel@tonic-gate } 22560Sstevel@tonic-gate } 22570Sstevel@tonic-gate 22580Sstevel@tonic-gate dstatp = (sbd_stat_t *)GETSTRUCT(char, sz); 22590Sstevel@tonic-gate 22600Sstevel@tonic-gate devstatp = &dstatp->s_stat[0]; 22610Sstevel@tonic-gate 22620Sstevel@tonic-gate dstatp->s_board = bp->b_num; 22630Sstevel@tonic-gate 22640Sstevel@tonic-gate /* 22650Sstevel@tonic-gate * Detect transitions between empty and disconnected. 22660Sstevel@tonic-gate */ 22670Sstevel@tonic-gate if (!pstat.empty && (bp->b_rstate == SBD_STAT_EMPTY)) 22680Sstevel@tonic-gate bp->b_rstate = SBD_STAT_DISCONNECTED; 22690Sstevel@tonic-gate else if (pstat.empty && (bp->b_rstate == SBD_STAT_DISCONNECTED)) 22700Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 22710Sstevel@tonic-gate 22720Sstevel@tonic-gate dstatp->s_rstate = bp->b_rstate; 22730Sstevel@tonic-gate dstatp->s_ostate = bp->b_ostate; 22740Sstevel@tonic-gate dstatp->s_cond = bp->b_cond = pstat.cond; 22750Sstevel@tonic-gate dstatp->s_busy = bp->b_busy | pstat.busy; 22760Sstevel@tonic-gate dstatp->s_time = bp->b_time; 22770Sstevel@tonic-gate dstatp->s_power = pstat.powered; 22780Sstevel@tonic-gate dstatp->s_assigned = bp->b_assigned = pstat.assigned; 22790Sstevel@tonic-gate dstatp->s_nstat = nstat = 0; 22800Sstevel@tonic-gate bcopy(&pstat.type[0], &dstatp->s_type[0], SBD_TYPE_LEN); 22810Sstevel@tonic-gate bcopy(&pstat.info[0], &dstatp->s_info[0], SBD_MAX_INFO); 22820Sstevel@tonic-gate 22830Sstevel@tonic-gate devset &= DR_DEVS_PRESENT(bp); 22840Sstevel@tonic-gate if (devset == 0) { 22850Sstevel@tonic-gate /* 22860Sstevel@tonic-gate * No device chosen. 22870Sstevel@tonic-gate */ 22880Sstevel@tonic-gate PR_ALL("%s: no device present\n", f); 22890Sstevel@tonic-gate } 22900Sstevel@tonic-gate 22910Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT)) 22920Sstevel@tonic-gate if ((nstat = dr_cpu_status(hp, devset, devstatp)) > 0) { 22930Sstevel@tonic-gate dstatp->s_nstat += nstat; 22940Sstevel@tonic-gate devstatp += nstat; 22950Sstevel@tonic-gate } 22960Sstevel@tonic-gate 22970Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT)) 22980Sstevel@tonic-gate if ((nstat = dr_mem_status(hp, devset, devstatp)) > 0) { 22990Sstevel@tonic-gate dstatp->s_nstat += nstat; 23000Sstevel@tonic-gate devstatp += nstat; 23010Sstevel@tonic-gate } 23020Sstevel@tonic-gate 23030Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT)) 23040Sstevel@tonic-gate if ((nstat = dr_io_status(hp, devset, devstatp)) > 0) { 23050Sstevel@tonic-gate dstatp->s_nstat += nstat; 23060Sstevel@tonic-gate devstatp += nstat; 23070Sstevel@tonic-gate } 23080Sstevel@tonic-gate 23090Sstevel@tonic-gate /* 23100Sstevel@tonic-gate * Due to a possible change in number of components between 23110Sstevel@tonic-gate * the time of plugin's GETNCM call and now, there may be 23120Sstevel@tonic-gate * more or less components than the plugin's buffer can 23130Sstevel@tonic-gate * hold. Adjust s_nstat accordingly. 23140Sstevel@tonic-gate */ 23150Sstevel@tonic-gate 23160Sstevel@tonic-gate dstatp->s_nstat = dstatp->s_nstat > pnstat ? pnstat : dstatp->s_nstat; 23170Sstevel@tonic-gate 23180Sstevel@tonic-gate 23190Sstevel@tonic-gate #ifdef _MULTI_DATAMODEL 23200Sstevel@tonic-gate if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) { 23210Sstevel@tonic-gate int i, j; 23220Sstevel@tonic-gate sbd_stat32_t *dstat32p; 23230Sstevel@tonic-gate 23240Sstevel@tonic-gate dstat32p = (sbd_stat32_t *)devstatp; 23250Sstevel@tonic-gate 23260Sstevel@tonic-gate /* Alignment Paranoia */ 23270Sstevel@tonic-gate if ((ulong_t)dstat32p & 0x1) { 2328930Smathue PR_ALL("%s: alignment: sz=0x%lx dstat32p=0x%p\n", 23290Sstevel@tonic-gate f, sizeof (sbd_stat32_t), dstat32p); 23300Sstevel@tonic-gate DR_OP_INTERNAL_ERROR(hp); 23310Sstevel@tonic-gate rv = EINVAL; 23320Sstevel@tonic-gate goto status_done; 23330Sstevel@tonic-gate } 23340Sstevel@tonic-gate 23350Sstevel@tonic-gate /* paranoia: detect buffer overrun */ 23360Sstevel@tonic-gate if ((caddr_t)&dstat32p->s_stat[dstatp->s_nstat] > 23370Sstevel@tonic-gate ((caddr_t)dstatp) + sz) { 23380Sstevel@tonic-gate DR_OP_INTERNAL_ERROR(hp); 23390Sstevel@tonic-gate rv = EINVAL; 23400Sstevel@tonic-gate goto status_done; 23410Sstevel@tonic-gate } 23420Sstevel@tonic-gate 23430Sstevel@tonic-gate /* copy sbd_stat_t structure members */ 23440Sstevel@tonic-gate #define _SBD_STAT(t, m) dstat32p->m = (t)dstatp->m 23450Sstevel@tonic-gate _SBD_STAT(int32_t, s_board); 23460Sstevel@tonic-gate _SBD_STAT(int32_t, s_rstate); 23470Sstevel@tonic-gate _SBD_STAT(int32_t, s_ostate); 23480Sstevel@tonic-gate _SBD_STAT(int32_t, s_cond); 23490Sstevel@tonic-gate _SBD_STAT(int32_t, s_busy); 23500Sstevel@tonic-gate _SBD_STAT(time32_t, s_time); 23510Sstevel@tonic-gate _SBD_STAT(uint32_t, s_power); 23520Sstevel@tonic-gate _SBD_STAT(uint32_t, s_assigned); 23530Sstevel@tonic-gate _SBD_STAT(int32_t, s_nstat); 23540Sstevel@tonic-gate bcopy(&dstatp->s_type[0], &dstat32p->s_type[0], 23550Sstevel@tonic-gate SBD_TYPE_LEN); 23560Sstevel@tonic-gate bcopy(&dstatp->s_info[0], &dstat32p->s_info[0], 23570Sstevel@tonic-gate SBD_MAX_INFO); 23580Sstevel@tonic-gate #undef _SBD_STAT 23590Sstevel@tonic-gate 23600Sstevel@tonic-gate for (i = 0; i < dstatp->s_nstat; i++) { 23610Sstevel@tonic-gate sbd_dev_stat_t *dsp = &dstatp->s_stat[i]; 23620Sstevel@tonic-gate sbd_dev_stat32_t *ds32p = &dstat32p->s_stat[i]; 23630Sstevel@tonic-gate #define _SBD_DEV_STAT(t, m) ds32p->m = (t)dsp->m 23640Sstevel@tonic-gate 23650Sstevel@tonic-gate /* copy sbd_cm_stat_t structure members */ 23660Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_type); 23670Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_unit); 23680Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_ostate); 23690Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_cond); 23700Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_busy); 23710Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, ds_suspend); 23720Sstevel@tonic-gate _SBD_DEV_STAT(time32_t, ds_time); 23730Sstevel@tonic-gate bcopy(&dsp->ds_name[0], &ds32p->ds_name[0], 23740Sstevel@tonic-gate OBP_MAXPROPNAME); 23750Sstevel@tonic-gate 23760Sstevel@tonic-gate switch (dsp->ds_type) { 23770Sstevel@tonic-gate case SBD_COMP_CPU: 23780Sstevel@tonic-gate /* copy sbd_cpu_stat_t structure members */ 23790Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_isbootproc); 23800Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_cpuid); 23810Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_speed); 23820Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cpu.cs_ecache); 23830Sstevel@tonic-gate break; 23840Sstevel@tonic-gate 23850Sstevel@tonic-gate case SBD_COMP_MEM: 23860Sstevel@tonic-gate /* copy sbd_mem_stat_t structure members */ 23870Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_interleave); 23880Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_basepfn); 23890Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_totpages); 23900Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_detpages); 23910Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_pageslost); 23920Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_managed_pages); 23930Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_pages); 23940Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_first); 23950Sstevel@tonic-gate _SBD_DEV_STAT(uint32_t, d_mem.ms_noreloc_last); 23960Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_cage_enabled); 23970Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_mem.ms_peer_is_target); 23980Sstevel@tonic-gate bcopy(&dsp->d_mem.ms_peer_ap_id[0], 23990Sstevel@tonic-gate &ds32p->d_mem.ms_peer_ap_id[0], 24000Sstevel@tonic-gate sizeof (ds32p->d_mem.ms_peer_ap_id)); 24010Sstevel@tonic-gate break; 24020Sstevel@tonic-gate 24030Sstevel@tonic-gate case SBD_COMP_IO: 24040Sstevel@tonic-gate /* copy sbd_io_stat_t structure members */ 24050Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_io.is_referenced); 24060Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_io.is_unsafe_count); 24070Sstevel@tonic-gate 24080Sstevel@tonic-gate for (j = 0; j < SBD_MAX_UNSAFE; j++) 24090Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, 24100Sstevel@tonic-gate d_io.is_unsafe_list[j]); 24110Sstevel@tonic-gate 24120Sstevel@tonic-gate bcopy(&dsp->d_io.is_pathname[0], 24130Sstevel@tonic-gate &ds32p->d_io.is_pathname[0], MAXPATHLEN); 24140Sstevel@tonic-gate break; 24150Sstevel@tonic-gate 24160Sstevel@tonic-gate case SBD_COMP_CMP: 24170Sstevel@tonic-gate /* copy sbd_cmp_stat_t structure members */ 24180Sstevel@tonic-gate bcopy(&dsp->d_cmp.ps_cpuid[0], 24190Sstevel@tonic-gate &ds32p->d_cmp.ps_cpuid[0], 24200Sstevel@tonic-gate sizeof (ds32p->d_cmp.ps_cpuid)); 24210Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_ncores); 24220Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_speed); 24230Sstevel@tonic-gate _SBD_DEV_STAT(int32_t, d_cmp.ps_ecache); 24240Sstevel@tonic-gate break; 24250Sstevel@tonic-gate 24260Sstevel@tonic-gate default: 24270Sstevel@tonic-gate cmn_err(CE_WARN, "%s: unknown dev type (%d)", 24280Sstevel@tonic-gate f, (int)dsp->ds_type); 24290Sstevel@tonic-gate rv = EFAULT; 24300Sstevel@tonic-gate goto status_done; 24310Sstevel@tonic-gate } 24320Sstevel@tonic-gate #undef _SBD_DEV_STAT 24330Sstevel@tonic-gate } 24340Sstevel@tonic-gate 24350Sstevel@tonic-gate 24360Sstevel@tonic-gate if (ddi_copyout((void *)dstat32p, 24370Sstevel@tonic-gate hp->h_sbdcmd.cmd_stat.s_statp, pbsz, mode) != 0) { 24380Sstevel@tonic-gate cmn_err(CE_WARN, 24390Sstevel@tonic-gate "%s: failed to copyout status " 24400Sstevel@tonic-gate "for board %d", f, bp->b_num); 24410Sstevel@tonic-gate rv = EFAULT; 24420Sstevel@tonic-gate goto status_done; 24430Sstevel@tonic-gate } 24440Sstevel@tonic-gate } else 24450Sstevel@tonic-gate #endif /* _MULTI_DATAMODEL */ 24460Sstevel@tonic-gate 24470Sstevel@tonic-gate if (ddi_copyout((void *)dstatp, hp->h_sbdcmd.cmd_stat.s_statp, 24480Sstevel@tonic-gate pbsz, mode) != 0) { 24490Sstevel@tonic-gate cmn_err(CE_WARN, 24500Sstevel@tonic-gate "%s: failed to copyout status for board %d", 24510Sstevel@tonic-gate f, bp->b_num); 24520Sstevel@tonic-gate rv = EFAULT; 24530Sstevel@tonic-gate goto status_done; 24540Sstevel@tonic-gate } 24550Sstevel@tonic-gate 24560Sstevel@tonic-gate status_done: 24570Sstevel@tonic-gate if (dstatp != NULL) 24580Sstevel@tonic-gate FREESTRUCT(dstatp, char, sz); 24590Sstevel@tonic-gate 24600Sstevel@tonic-gate dr_unlock_status(bp); 24610Sstevel@tonic-gate 24620Sstevel@tonic-gate return (rv); 24630Sstevel@tonic-gate } 24640Sstevel@tonic-gate 24650Sstevel@tonic-gate static int 24660Sstevel@tonic-gate dr_get_ncm(dr_handle_t *hp) 24670Sstevel@tonic-gate { 24680Sstevel@tonic-gate int i; 24690Sstevel@tonic-gate int ncm = 0; 24700Sstevel@tonic-gate dr_devset_t devset; 24710Sstevel@tonic-gate 24720Sstevel@tonic-gate devset = DR_DEVS_PRESENT(hp->h_bd); 24730Sstevel@tonic-gate if (hp->h_sbdcmd.cmd_cm.c_id.c_type != SBD_COMP_NONE) 24740Sstevel@tonic-gate devset &= DEVSET(hp->h_sbdcmd.cmd_cm.c_id.c_type, 2475*1772Sjl139090 DEVSET_ANYUNIT); 24760Sstevel@tonic-gate 24770Sstevel@tonic-gate /* 24780Sstevel@tonic-gate * Handle CPUs first to deal with possible CMP 24790Sstevel@tonic-gate * devices. If the CPU is a CMP, we need to only 24800Sstevel@tonic-gate * increment ncm once even if there are multiple 24810Sstevel@tonic-gate * cores for that CMP present in the devset. 24820Sstevel@tonic-gate */ 24830Sstevel@tonic-gate for (i = 0; i < MAX_CMP_UNITS_PER_BOARD; i++) { 24840Sstevel@tonic-gate if (devset & DEVSET(SBD_COMP_CMP, i)) { 24850Sstevel@tonic-gate ncm++; 24860Sstevel@tonic-gate } 24870Sstevel@tonic-gate } 24880Sstevel@tonic-gate 24890Sstevel@tonic-gate /* eliminate the CPU information from the devset */ 24900Sstevel@tonic-gate devset &= ~(DEVSET(SBD_COMP_CMP, DEVSET_ANYUNIT)); 24910Sstevel@tonic-gate 24920Sstevel@tonic-gate for (i = 0; i < (sizeof (dr_devset_t) * 8); i++) { 24930Sstevel@tonic-gate ncm += devset & 0x1; 24940Sstevel@tonic-gate devset >>= 1; 24950Sstevel@tonic-gate } 24960Sstevel@tonic-gate 24970Sstevel@tonic-gate return (ncm); 24980Sstevel@tonic-gate } 24990Sstevel@tonic-gate 25000Sstevel@tonic-gate /* used by dr_mem.c */ 25010Sstevel@tonic-gate /* TODO: eliminate dr_boardlist */ 25020Sstevel@tonic-gate dr_board_t * 25030Sstevel@tonic-gate dr_lookup_board(int board_num) 25040Sstevel@tonic-gate { 25050Sstevel@tonic-gate dr_board_t *bp; 25060Sstevel@tonic-gate 25070Sstevel@tonic-gate ASSERT(board_num >= 0 && board_num < MAX_BOARDS); 25080Sstevel@tonic-gate 25090Sstevel@tonic-gate bp = &dr_boardlist[board_num]; 25100Sstevel@tonic-gate ASSERT(bp->b_num == board_num); 25110Sstevel@tonic-gate 25120Sstevel@tonic-gate return (bp); 25130Sstevel@tonic-gate } 25140Sstevel@tonic-gate 25150Sstevel@tonic-gate static dr_dev_unit_t * 25160Sstevel@tonic-gate dr_get_dev_unit(dr_board_t *bp, sbd_comp_type_t nt, int unit_num) 25170Sstevel@tonic-gate { 25180Sstevel@tonic-gate dr_dev_unit_t *dp; 25190Sstevel@tonic-gate 25200Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, nt, unit_num); 25210Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_bp == bp); 25220Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_unum == unit_num); 25230Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_type == nt); 25240Sstevel@tonic-gate 25250Sstevel@tonic-gate return (dp); 25260Sstevel@tonic-gate } 25270Sstevel@tonic-gate 25280Sstevel@tonic-gate dr_cpu_unit_t * 25290Sstevel@tonic-gate dr_get_cpu_unit(dr_board_t *bp, int unit_num) 25300Sstevel@tonic-gate { 25310Sstevel@tonic-gate dr_dev_unit_t *dp; 25320Sstevel@tonic-gate 25330Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_CPU_UNITS_PER_BOARD); 25340Sstevel@tonic-gate 25350Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_CPU, unit_num); 25360Sstevel@tonic-gate return (&dp->du_cpu); 25370Sstevel@tonic-gate } 25380Sstevel@tonic-gate 25390Sstevel@tonic-gate dr_mem_unit_t * 25400Sstevel@tonic-gate dr_get_mem_unit(dr_board_t *bp, int unit_num) 25410Sstevel@tonic-gate { 25420Sstevel@tonic-gate dr_dev_unit_t *dp; 25430Sstevel@tonic-gate 25440Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_MEM_UNITS_PER_BOARD); 25450Sstevel@tonic-gate 25460Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_MEM, unit_num); 25470Sstevel@tonic-gate return (&dp->du_mem); 25480Sstevel@tonic-gate } 25490Sstevel@tonic-gate 25500Sstevel@tonic-gate dr_io_unit_t * 25510Sstevel@tonic-gate dr_get_io_unit(dr_board_t *bp, int unit_num) 25520Sstevel@tonic-gate { 25530Sstevel@tonic-gate dr_dev_unit_t *dp; 25540Sstevel@tonic-gate 25550Sstevel@tonic-gate ASSERT(unit_num >= 0 && unit_num < MAX_IO_UNITS_PER_BOARD); 25560Sstevel@tonic-gate 25570Sstevel@tonic-gate dp = dr_get_dev_unit(bp, SBD_COMP_IO, unit_num); 25580Sstevel@tonic-gate return (&dp->du_io); 25590Sstevel@tonic-gate } 25600Sstevel@tonic-gate 25610Sstevel@tonic-gate dr_common_unit_t * 25620Sstevel@tonic-gate dr_get_common_unit(dr_board_t *bp, sbd_comp_type_t nt, int unum) 25630Sstevel@tonic-gate { 25640Sstevel@tonic-gate dr_dev_unit_t *dp; 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate dp = dr_get_dev_unit(bp, nt, unum); 25670Sstevel@tonic-gate return (&dp->du_common); 25680Sstevel@tonic-gate } 25690Sstevel@tonic-gate 25700Sstevel@tonic-gate static dr_devset_t 25710Sstevel@tonic-gate dr_dev2devset(sbd_comp_id_t *cid) 25720Sstevel@tonic-gate { 25730Sstevel@tonic-gate static fn_t f = "dr_dev2devset"; 25740Sstevel@tonic-gate 25750Sstevel@tonic-gate dr_devset_t devset; 25760Sstevel@tonic-gate int unit = cid->c_unit; 25770Sstevel@tonic-gate 25780Sstevel@tonic-gate switch (cid->c_type) { 25790Sstevel@tonic-gate case SBD_COMP_NONE: 25800Sstevel@tonic-gate devset = DEVSET(SBD_COMP_CPU, DEVSET_ANYUNIT); 25810Sstevel@tonic-gate devset |= DEVSET(SBD_COMP_MEM, DEVSET_ANYUNIT); 25820Sstevel@tonic-gate devset |= DEVSET(SBD_COMP_IO, DEVSET_ANYUNIT); 2583*1772Sjl139090 PR_ALL("%s: COMP_NONE devset = 0x%lx\n", f, devset); 25840Sstevel@tonic-gate break; 25850Sstevel@tonic-gate 25860Sstevel@tonic-gate case SBD_COMP_CPU: 25870Sstevel@tonic-gate if ((unit > MAX_CPU_UNITS_PER_BOARD) || (unit < 0)) { 25880Sstevel@tonic-gate cmn_err(CE_WARN, 25890Sstevel@tonic-gate "%s: invalid cpu unit# = %d", 25900Sstevel@tonic-gate f, unit); 25910Sstevel@tonic-gate devset = 0; 25920Sstevel@tonic-gate } else { 25930Sstevel@tonic-gate /* 25940Sstevel@tonic-gate * Generate a devset that includes all the 25950Sstevel@tonic-gate * cores of a CMP device. If this is not a 25960Sstevel@tonic-gate * CMP, the extra cores will be eliminated 25970Sstevel@tonic-gate * later since they are not present. This is 25980Sstevel@tonic-gate * also true for CMP devices that do not have 25990Sstevel@tonic-gate * all cores active. 26000Sstevel@tonic-gate */ 26010Sstevel@tonic-gate devset = DEVSET(SBD_COMP_CMP, unit); 26020Sstevel@tonic-gate } 26030Sstevel@tonic-gate 2604*1772Sjl139090 PR_ALL("%s: CPU devset = 0x%lx\n", f, devset); 26050Sstevel@tonic-gate break; 26060Sstevel@tonic-gate 26070Sstevel@tonic-gate case SBD_COMP_MEM: 26080Sstevel@tonic-gate if (unit == SBD_NULL_UNIT) { 26090Sstevel@tonic-gate unit = 0; 26100Sstevel@tonic-gate cid->c_unit = 0; 26110Sstevel@tonic-gate } 26120Sstevel@tonic-gate 26130Sstevel@tonic-gate if ((unit > MAX_MEM_UNITS_PER_BOARD) || (unit < 0)) { 26140Sstevel@tonic-gate cmn_err(CE_WARN, 26150Sstevel@tonic-gate "%s: invalid mem unit# = %d", 26160Sstevel@tonic-gate f, unit); 26170Sstevel@tonic-gate devset = 0; 26180Sstevel@tonic-gate } else 26190Sstevel@tonic-gate devset = DEVSET(cid->c_type, unit); 26200Sstevel@tonic-gate 2621*1772Sjl139090 PR_ALL("%s: MEM devset = 0x%lx\n", f, devset); 26220Sstevel@tonic-gate break; 26230Sstevel@tonic-gate 26240Sstevel@tonic-gate case SBD_COMP_IO: 26250Sstevel@tonic-gate if ((unit > MAX_IO_UNITS_PER_BOARD) || (unit < 0)) { 26260Sstevel@tonic-gate cmn_err(CE_WARN, 26270Sstevel@tonic-gate "%s: invalid io unit# = %d", 26280Sstevel@tonic-gate f, unit); 26290Sstevel@tonic-gate devset = 0; 26300Sstevel@tonic-gate } else 26310Sstevel@tonic-gate devset = DEVSET(cid->c_type, unit); 26320Sstevel@tonic-gate 2633*1772Sjl139090 PR_ALL("%s: IO devset = 0x%lx\n", f, devset); 26340Sstevel@tonic-gate break; 26350Sstevel@tonic-gate 26360Sstevel@tonic-gate default: 26370Sstevel@tonic-gate case SBD_COMP_UNKNOWN: 26380Sstevel@tonic-gate devset = 0; 26390Sstevel@tonic-gate break; 26400Sstevel@tonic-gate } 26410Sstevel@tonic-gate 26420Sstevel@tonic-gate return (devset); 26430Sstevel@tonic-gate } 26440Sstevel@tonic-gate 26450Sstevel@tonic-gate /* 26460Sstevel@tonic-gate * Converts a dynamic attachment point name to a SBD_COMP_* type. 26470Sstevel@tonic-gate * Returns SDB_COMP_UNKNOWN if name is not recognized. 26480Sstevel@tonic-gate */ 26490Sstevel@tonic-gate static int 26500Sstevel@tonic-gate dr_dev_type_to_nt(char *type) 26510Sstevel@tonic-gate { 26520Sstevel@tonic-gate int i; 26530Sstevel@tonic-gate 26540Sstevel@tonic-gate for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++) 26550Sstevel@tonic-gate if (strcmp(dr_devattr[i].s_devtype, type) == 0) 26560Sstevel@tonic-gate break; 26570Sstevel@tonic-gate 26580Sstevel@tonic-gate return (dr_devattr[i].s_nodetype); 26590Sstevel@tonic-gate } 26600Sstevel@tonic-gate 26610Sstevel@tonic-gate /* 26620Sstevel@tonic-gate * Converts a SBD_COMP_* type to a dynamic attachment point name. 26630Sstevel@tonic-gate * Return NULL if SBD_COMP_ type is not recognized. 26640Sstevel@tonic-gate */ 26650Sstevel@tonic-gate char * 26660Sstevel@tonic-gate dr_nt_to_dev_type(int nt) 26670Sstevel@tonic-gate { 26680Sstevel@tonic-gate int i; 26690Sstevel@tonic-gate 26700Sstevel@tonic-gate for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++) 26710Sstevel@tonic-gate if (dr_devattr[i].s_nodetype == nt) 26720Sstevel@tonic-gate break; 26730Sstevel@tonic-gate 26740Sstevel@tonic-gate return (dr_devattr[i].s_devtype); 26750Sstevel@tonic-gate } 26760Sstevel@tonic-gate 26770Sstevel@tonic-gate 26780Sstevel@tonic-gate /* 26790Sstevel@tonic-gate * State transition policy is that if there is some component for which 26800Sstevel@tonic-gate * the state transition is valid, then let it through. The exception is 26810Sstevel@tonic-gate * SBD_CMD_DISCONNECT. On disconnect, the state transition must be valid 26820Sstevel@tonic-gate * for ALL components. 26830Sstevel@tonic-gate * Returns the state that is in error, if any. 26840Sstevel@tonic-gate */ 26850Sstevel@tonic-gate static int 26860Sstevel@tonic-gate dr_check_transition(dr_board_t *bp, dr_devset_t *devsetp, 26870Sstevel@tonic-gate struct dr_state_trans *transp, int cmd) 26880Sstevel@tonic-gate { 26890Sstevel@tonic-gate int s, ut; 26900Sstevel@tonic-gate int state_err = 0; 26910Sstevel@tonic-gate dr_devset_t devset; 26920Sstevel@tonic-gate dr_common_unit_t *cp; 26930Sstevel@tonic-gate static fn_t f = "dr_check_transition"; 26940Sstevel@tonic-gate 26950Sstevel@tonic-gate devset = *devsetp; 26960Sstevel@tonic-gate 26970Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT)) { 26980Sstevel@tonic-gate for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) { 26990Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_CPU, ut) == 0) 27000Sstevel@tonic-gate continue; 27010Sstevel@tonic-gate 27020Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_CPU, ut); 27030Sstevel@tonic-gate s = (int)cp->sbdev_state; 27040Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27050Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_CPU, ut); 27060Sstevel@tonic-gate } else { 27070Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27080Sstevel@tonic-gate if (!state_err) 27090Sstevel@tonic-gate state_err = s; 27100Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_CPU, ut); 27110Sstevel@tonic-gate } 27120Sstevel@tonic-gate } 27130Sstevel@tonic-gate } 27140Sstevel@tonic-gate } 27150Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT)) { 27160Sstevel@tonic-gate for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) { 27170Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_MEM, ut) == 0) 27180Sstevel@tonic-gate continue; 27190Sstevel@tonic-gate 27200Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_MEM, ut); 27210Sstevel@tonic-gate s = (int)cp->sbdev_state; 27220Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27230Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_MEM, ut); 27240Sstevel@tonic-gate } else { 27250Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27260Sstevel@tonic-gate if (!state_err) 27270Sstevel@tonic-gate state_err = s; 27280Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_MEM, ut); 27290Sstevel@tonic-gate } 27300Sstevel@tonic-gate } 27310Sstevel@tonic-gate } 27320Sstevel@tonic-gate } 27330Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT)) { 27340Sstevel@tonic-gate for (ut = 0; ut < MAX_IO_UNITS_PER_BOARD; ut++) { 27350Sstevel@tonic-gate if (DEVSET_IN_SET(devset, SBD_COMP_IO, ut) == 0) 27360Sstevel@tonic-gate continue; 27370Sstevel@tonic-gate 27380Sstevel@tonic-gate cp = dr_get_common_unit(bp, SBD_COMP_IO, ut); 27390Sstevel@tonic-gate s = (int)cp->sbdev_state; 27400Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(cp)) { 27410Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_IO, ut); 27420Sstevel@tonic-gate } else { 27430Sstevel@tonic-gate if (transp->x_op[s].x_rv) { 27440Sstevel@tonic-gate if (!state_err) 27450Sstevel@tonic-gate state_err = s; 27460Sstevel@tonic-gate DEVSET_DEL(devset, SBD_COMP_IO, ut); 27470Sstevel@tonic-gate } 27480Sstevel@tonic-gate } 27490Sstevel@tonic-gate } 27500Sstevel@tonic-gate } 27510Sstevel@tonic-gate 27520Sstevel@tonic-gate PR_ALL("%s: requested devset = 0x%x, final devset = 0x%x\n", 27530Sstevel@tonic-gate f, (uint_t)*devsetp, (uint_t)devset); 27540Sstevel@tonic-gate 27550Sstevel@tonic-gate *devsetp = devset; 27560Sstevel@tonic-gate /* 27570Sstevel@tonic-gate * If there are some remaining components for which 27580Sstevel@tonic-gate * this state transition is valid, then allow them 27590Sstevel@tonic-gate * through, otherwise if none are left then return 27600Sstevel@tonic-gate * the state error. The exception is SBD_CMD_DISCONNECT. 27610Sstevel@tonic-gate * On disconnect, the state transition must be valid for ALL 27620Sstevel@tonic-gate * components. 27630Sstevel@tonic-gate */ 27640Sstevel@tonic-gate if (cmd == SBD_CMD_DISCONNECT) 27650Sstevel@tonic-gate return (state_err); 27660Sstevel@tonic-gate return (devset ? 0 : state_err); 27670Sstevel@tonic-gate } 27680Sstevel@tonic-gate 27690Sstevel@tonic-gate void 27700Sstevel@tonic-gate dr_device_transition(dr_common_unit_t *cp, dr_state_t st) 27710Sstevel@tonic-gate { 27720Sstevel@tonic-gate PR_STATE("%s STATE %s(%d) -> %s(%d)\n", 27730Sstevel@tonic-gate cp->sbdev_path, 27740Sstevel@tonic-gate state_str[cp->sbdev_state], cp->sbdev_state, 27750Sstevel@tonic-gate state_str[st], st); 27760Sstevel@tonic-gate 27770Sstevel@tonic-gate cp->sbdev_state = st; 27780Sstevel@tonic-gate if (st == DR_STATE_CONFIGURED) { 27790Sstevel@tonic-gate cp->sbdev_ostate = SBD_STAT_CONFIGURED; 27800Sstevel@tonic-gate if (cp->sbdev_bp->b_ostate != SBD_STAT_CONFIGURED) { 27810Sstevel@tonic-gate cp->sbdev_bp->b_ostate = SBD_STAT_CONFIGURED; 27820Sstevel@tonic-gate (void) drv_getparm(TIME, 27830Sstevel@tonic-gate (void *) &cp->sbdev_bp->b_time); 27840Sstevel@tonic-gate } 27850Sstevel@tonic-gate } else 27860Sstevel@tonic-gate cp->sbdev_ostate = SBD_STAT_UNCONFIGURED; 27870Sstevel@tonic-gate 27880Sstevel@tonic-gate (void) drv_getparm(TIME, (void *) &cp->sbdev_time); 27890Sstevel@tonic-gate } 27900Sstevel@tonic-gate 27910Sstevel@tonic-gate static void 27920Sstevel@tonic-gate dr_board_transition(dr_board_t *bp, dr_state_t st) 27930Sstevel@tonic-gate { 27940Sstevel@tonic-gate PR_STATE("BOARD %d STATE: %s(%d) -> %s(%d)\n", 27950Sstevel@tonic-gate bp->b_num, 27960Sstevel@tonic-gate state_str[bp->b_state], bp->b_state, 27970Sstevel@tonic-gate state_str[st], st); 27980Sstevel@tonic-gate 27990Sstevel@tonic-gate bp->b_state = st; 28000Sstevel@tonic-gate } 28010Sstevel@tonic-gate 28020Sstevel@tonic-gate void 28030Sstevel@tonic-gate dr_op_err(int ce, dr_handle_t *hp, int code, char *fmt, ...) 28040Sstevel@tonic-gate { 28050Sstevel@tonic-gate sbd_error_t *err; 28060Sstevel@tonic-gate va_list args; 28070Sstevel@tonic-gate 28080Sstevel@tonic-gate va_start(args, fmt); 28090Sstevel@tonic-gate err = drerr_new_v(code, fmt, args); 28100Sstevel@tonic-gate va_end(args); 28110Sstevel@tonic-gate 28120Sstevel@tonic-gate if (ce != CE_IGNORE) 28130Sstevel@tonic-gate sbd_err_log(err, ce); 28140Sstevel@tonic-gate 28150Sstevel@tonic-gate DRERR_SET_C(&hp->h_err, &err); 28160Sstevel@tonic-gate } 28170Sstevel@tonic-gate 28180Sstevel@tonic-gate void 28190Sstevel@tonic-gate dr_dev_err(int ce, dr_common_unit_t *cp, int code) 28200Sstevel@tonic-gate { 28210Sstevel@tonic-gate sbd_error_t *err; 28220Sstevel@tonic-gate 28230Sstevel@tonic-gate err = drerr_new(0, code, cp->sbdev_path, NULL); 28240Sstevel@tonic-gate 28250Sstevel@tonic-gate if (ce != CE_IGNORE) 28260Sstevel@tonic-gate sbd_err_log(err, ce); 28270Sstevel@tonic-gate 28280Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 28290Sstevel@tonic-gate } 28300Sstevel@tonic-gate 28310Sstevel@tonic-gate /* 28320Sstevel@tonic-gate * A callback routine. Called from the drmach layer as a result of 28330Sstevel@tonic-gate * call to drmach_board_find_devices from dr_init_devlists. 28340Sstevel@tonic-gate */ 28350Sstevel@tonic-gate static sbd_error_t * 28360Sstevel@tonic-gate dr_dev_found(void *data, const char *name, int unum, drmachid_t id) 28370Sstevel@tonic-gate { 28380Sstevel@tonic-gate dr_board_t *bp = data; 28390Sstevel@tonic-gate dr_dev_unit_t *dp; 28400Sstevel@tonic-gate int nt; 28410Sstevel@tonic-gate static fn_t f = "dr_dev_found"; 28420Sstevel@tonic-gate 28430Sstevel@tonic-gate PR_ALL("%s (board = %d, name = %s, unum = %d, id = %p)...\n", 28440Sstevel@tonic-gate f, bp->b_num, name, unum, id); 28450Sstevel@tonic-gate 28460Sstevel@tonic-gate nt = dr_dev_type_to_nt((char *)name); 28470Sstevel@tonic-gate if (nt == SBD_COMP_UNKNOWN) { 28480Sstevel@tonic-gate /* 28490Sstevel@tonic-gate * this should not happen. When it does, it indicates 28500Sstevel@tonic-gate * a missmatch in devices supported by the drmach layer 28510Sstevel@tonic-gate * vs devices supported by this layer. 28520Sstevel@tonic-gate */ 28530Sstevel@tonic-gate return (DR_INTERNAL_ERROR()); 28540Sstevel@tonic-gate } 28550Sstevel@tonic-gate 28560Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, nt, unum); 28570Sstevel@tonic-gate 28580Sstevel@tonic-gate /* sanity check */ 28590Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_bp == bp); 28600Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_unum == unum); 28610Sstevel@tonic-gate ASSERT(dp->du_common.sbdev_type == nt); 28620Sstevel@tonic-gate 28630Sstevel@tonic-gate /* render dynamic attachment point path of this unit */ 28640Sstevel@tonic-gate (void) snprintf(dp->du_common.sbdev_path, 2865*1772Sjl139090 sizeof (dp->du_common.sbdev_path), 2866*1772Sjl139090 (nt == SBD_COMP_MEM ? "%s::%s" : "%s::%s%d"), 2867*1772Sjl139090 bp->b_path, name, DR_UNUM2SBD_UNUM(unum, nt)); 28680Sstevel@tonic-gate 28690Sstevel@tonic-gate dp->du_common.sbdev_id = id; 28700Sstevel@tonic-gate DR_DEV_SET_PRESENT(&dp->du_common); 28710Sstevel@tonic-gate 28720Sstevel@tonic-gate bp->b_ndev++; 28730Sstevel@tonic-gate 28740Sstevel@tonic-gate return (NULL); 28750Sstevel@tonic-gate } 28760Sstevel@tonic-gate 28770Sstevel@tonic-gate static sbd_error_t * 28780Sstevel@tonic-gate dr_init_devlists(dr_board_t *bp) 28790Sstevel@tonic-gate { 28800Sstevel@tonic-gate int i; 28810Sstevel@tonic-gate sbd_error_t *err; 28820Sstevel@tonic-gate dr_dev_unit_t *dp; 28830Sstevel@tonic-gate static fn_t f = "dr_init_devlists"; 28840Sstevel@tonic-gate 28850Sstevel@tonic-gate PR_ALL("%s (%s)...\n", f, bp->b_path); 28860Sstevel@tonic-gate 28870Sstevel@tonic-gate /* sanity check */ 28880Sstevel@tonic-gate ASSERT(bp->b_ndev == 0); 28890Sstevel@tonic-gate 28900Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, (uint_t)-1); 28910Sstevel@tonic-gate 28920Sstevel@tonic-gate /* 28930Sstevel@tonic-gate * This routine builds the board's devlist and initializes 28940Sstevel@tonic-gate * the common portion of the unit data structures. 28950Sstevel@tonic-gate * Note: because the common portion is considered 28960Sstevel@tonic-gate * uninitialized, the dr_get_*_unit() routines can not 28970Sstevel@tonic-gate * be used. 28980Sstevel@tonic-gate */ 28990Sstevel@tonic-gate 29000Sstevel@tonic-gate /* 29010Sstevel@tonic-gate * Clear out old entries, if any. 29020Sstevel@tonic-gate */ 29030Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 29040Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_CPU, i); 29050Sstevel@tonic-gate 29060Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29070Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29080Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29090Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_CPU; 29100Sstevel@tonic-gate } 29110Sstevel@tonic-gate 29120Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 29130Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_MEM, i); 29140Sstevel@tonic-gate 29150Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29160Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29170Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29180Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_MEM; 29190Sstevel@tonic-gate } 29200Sstevel@tonic-gate 29210Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 29220Sstevel@tonic-gate dp = DR_GET_BOARD_DEVUNIT(bp, SBD_COMP_IO, i); 29230Sstevel@tonic-gate 29240Sstevel@tonic-gate bzero(dp, sizeof (*dp)); 29250Sstevel@tonic-gate dp->du_common.sbdev_bp = bp; 29260Sstevel@tonic-gate dp->du_common.sbdev_unum = i; 29270Sstevel@tonic-gate dp->du_common.sbdev_type = SBD_COMP_IO; 29280Sstevel@tonic-gate } 29290Sstevel@tonic-gate 29300Sstevel@tonic-gate err = NULL; 29310Sstevel@tonic-gate if (bp->b_id) { 29320Sstevel@tonic-gate /* find devices on this board */ 29330Sstevel@tonic-gate err = drmach_board_find_devices( 29340Sstevel@tonic-gate bp->b_id, bp, dr_dev_found); 29350Sstevel@tonic-gate } 29360Sstevel@tonic-gate 29370Sstevel@tonic-gate return (err); 29380Sstevel@tonic-gate } 29390Sstevel@tonic-gate 29400Sstevel@tonic-gate /* 29410Sstevel@tonic-gate * Return the unit number of the respective drmachid if 29420Sstevel@tonic-gate * it's found to be attached. 29430Sstevel@tonic-gate */ 29440Sstevel@tonic-gate static int 29450Sstevel@tonic-gate dr_check_unit_attached(dr_common_unit_t *cp) 29460Sstevel@tonic-gate { 29470Sstevel@tonic-gate int rv = 0; 29480Sstevel@tonic-gate processorid_t cpuid; 29490Sstevel@tonic-gate uint64_t basepa, endpa; 29500Sstevel@tonic-gate struct memlist *ml; 29510Sstevel@tonic-gate extern struct memlist *phys_install; 29520Sstevel@tonic-gate sbd_error_t *err; 29530Sstevel@tonic-gate int yes; 29540Sstevel@tonic-gate static fn_t f = "dr_check_unit_attached"; 29550Sstevel@tonic-gate 29560Sstevel@tonic-gate switch (cp->sbdev_type) { 29570Sstevel@tonic-gate case SBD_COMP_CPU: 29580Sstevel@tonic-gate err = drmach_cpu_get_id(cp->sbdev_id, &cpuid); 29590Sstevel@tonic-gate if (err) { 29600Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29610Sstevel@tonic-gate rv = -1; 29620Sstevel@tonic-gate break; 29630Sstevel@tonic-gate } 29640Sstevel@tonic-gate mutex_enter(&cpu_lock); 29650Sstevel@tonic-gate if (cpu_get(cpuid) == NULL) 29660Sstevel@tonic-gate rv = -1; 29670Sstevel@tonic-gate mutex_exit(&cpu_lock); 29680Sstevel@tonic-gate break; 29690Sstevel@tonic-gate 29700Sstevel@tonic-gate case SBD_COMP_MEM: 29710Sstevel@tonic-gate err = drmach_mem_get_base_physaddr(cp->sbdev_id, &basepa); 29720Sstevel@tonic-gate if (err) { 29730Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29740Sstevel@tonic-gate rv = -1; 29750Sstevel@tonic-gate break; 29760Sstevel@tonic-gate } 29770Sstevel@tonic-gate 29780Sstevel@tonic-gate /* 29790Sstevel@tonic-gate * basepa may not be on a alignment boundary, make it so. 29800Sstevel@tonic-gate */ 29810Sstevel@tonic-gate err = drmach_mem_get_slice_size(cp->sbdev_id, &endpa); 29820Sstevel@tonic-gate if (err) { 29830Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 29840Sstevel@tonic-gate rv = -1; 29850Sstevel@tonic-gate break; 29860Sstevel@tonic-gate } 29870Sstevel@tonic-gate 29880Sstevel@tonic-gate basepa &= ~(endpa - 1); 29890Sstevel@tonic-gate endpa += basepa; 29900Sstevel@tonic-gate 29910Sstevel@tonic-gate /* 29920Sstevel@tonic-gate * Check if base address is in phys_install. 29930Sstevel@tonic-gate */ 29940Sstevel@tonic-gate memlist_read_lock(); 29950Sstevel@tonic-gate for (ml = phys_install; ml; ml = ml->next) 29960Sstevel@tonic-gate if ((endpa <= ml->address) || 2997*1772Sjl139090 (basepa >= (ml->address + ml->size))) 29980Sstevel@tonic-gate continue; 29990Sstevel@tonic-gate else 30000Sstevel@tonic-gate break; 30010Sstevel@tonic-gate memlist_read_unlock(); 30020Sstevel@tonic-gate if (ml == NULL) 30030Sstevel@tonic-gate rv = -1; 30040Sstevel@tonic-gate break; 30050Sstevel@tonic-gate 30060Sstevel@tonic-gate case SBD_COMP_IO: 30070Sstevel@tonic-gate err = drmach_io_is_attached(cp->sbdev_id, &yes); 30080Sstevel@tonic-gate if (err) { 30090Sstevel@tonic-gate DRERR_SET_C(&cp->sbdev_error, &err); 30100Sstevel@tonic-gate rv = -1; 30110Sstevel@tonic-gate break; 30120Sstevel@tonic-gate } else if (!yes) 30130Sstevel@tonic-gate rv = -1; 30140Sstevel@tonic-gate break; 30150Sstevel@tonic-gate 30160Sstevel@tonic-gate default: 3017930Smathue PR_ALL("%s: unexpected nodetype(%d) for id 0x%p\n", 30180Sstevel@tonic-gate f, cp->sbdev_type, cp->sbdev_id); 30190Sstevel@tonic-gate rv = -1; 30200Sstevel@tonic-gate break; 30210Sstevel@tonic-gate } 30220Sstevel@tonic-gate 30230Sstevel@tonic-gate return (rv); 30240Sstevel@tonic-gate } 30250Sstevel@tonic-gate 30260Sstevel@tonic-gate /* 30270Sstevel@tonic-gate * See if drmach recognizes the passthru command. DRMACH expects the 30280Sstevel@tonic-gate * id to identify the thing to which the command is being applied. Using 30290Sstevel@tonic-gate * nonsense SBD terms, that information has been perversely encoded in the 30300Sstevel@tonic-gate * c_id member of the sbd_cmd_t structure. This logic reads those tea 30310Sstevel@tonic-gate * leaves, finds the associated drmach id, then calls drmach to process 30320Sstevel@tonic-gate * the passthru command. 30330Sstevel@tonic-gate */ 30340Sstevel@tonic-gate static int 30350Sstevel@tonic-gate dr_pt_try_drmach(dr_handle_t *hp) 30360Sstevel@tonic-gate { 30370Sstevel@tonic-gate dr_board_t *bp = hp->h_bd; 30380Sstevel@tonic-gate sbd_comp_id_t *comp_id = &hp->h_sbdcmd.cmd_cm.c_id; 30390Sstevel@tonic-gate drmachid_t id; 30400Sstevel@tonic-gate 30410Sstevel@tonic-gate if (comp_id->c_type == SBD_COMP_NONE) { 30420Sstevel@tonic-gate id = bp->b_id; 30430Sstevel@tonic-gate } else { 30440Sstevel@tonic-gate sbd_comp_type_t nt; 30450Sstevel@tonic-gate 30460Sstevel@tonic-gate nt = dr_dev_type_to_nt(comp_id->c_name); 30470Sstevel@tonic-gate if (nt == SBD_COMP_UNKNOWN) { 30480Sstevel@tonic-gate dr_op_err(CE_IGNORE, hp, ESBD_INVAL, comp_id->c_name); 30490Sstevel@tonic-gate id = 0; 30500Sstevel@tonic-gate } else { 30510Sstevel@tonic-gate /* pt command applied to dynamic attachment point */ 30520Sstevel@tonic-gate dr_common_unit_t *cp; 30530Sstevel@tonic-gate cp = dr_get_common_unit(bp, nt, comp_id->c_unit); 30540Sstevel@tonic-gate id = cp->sbdev_id; 30550Sstevel@tonic-gate } 30560Sstevel@tonic-gate } 30570Sstevel@tonic-gate 30580Sstevel@tonic-gate if (hp->h_err == NULL) 30590Sstevel@tonic-gate hp->h_err = drmach_passthru(id, &hp->h_opts); 30600Sstevel@tonic-gate 30610Sstevel@tonic-gate return (hp->h_err == NULL ? 0 : -1); 30620Sstevel@tonic-gate } 30630Sstevel@tonic-gate 30640Sstevel@tonic-gate static int 30650Sstevel@tonic-gate dr_pt_ioctl(dr_handle_t *hp) 30660Sstevel@tonic-gate { 30670Sstevel@tonic-gate int cmd, rv, len; 30680Sstevel@tonic-gate int32_t sz; 30690Sstevel@tonic-gate int found; 30700Sstevel@tonic-gate char *copts; 30710Sstevel@tonic-gate static fn_t f = "dr_pt_ioctl"; 30720Sstevel@tonic-gate 30730Sstevel@tonic-gate PR_ALL("%s...\n", f); 30740Sstevel@tonic-gate 30750Sstevel@tonic-gate sz = hp->h_opts.size; 30760Sstevel@tonic-gate copts = hp->h_opts.copts; 30770Sstevel@tonic-gate 30780Sstevel@tonic-gate if (sz == 0 || copts == (char *)NULL) { 30790Sstevel@tonic-gate cmn_err(CE_WARN, "%s: invalid passthru args", f); 30800Sstevel@tonic-gate return (EINVAL); 30810Sstevel@tonic-gate } 30820Sstevel@tonic-gate 30830Sstevel@tonic-gate found = 0; 30840Sstevel@tonic-gate for (cmd = 0; cmd < (sizeof (pt_arr) / sizeof (pt_arr[0])); cmd++) { 30850Sstevel@tonic-gate len = strlen(pt_arr[cmd].pt_name); 30860Sstevel@tonic-gate found = (strncmp(pt_arr[cmd].pt_name, copts, len) == 0); 30870Sstevel@tonic-gate if (found) 30880Sstevel@tonic-gate break; 30890Sstevel@tonic-gate } 30900Sstevel@tonic-gate 30910Sstevel@tonic-gate if (found) 30920Sstevel@tonic-gate rv = (*pt_arr[cmd].pt_func)(hp); 30930Sstevel@tonic-gate else 30940Sstevel@tonic-gate rv = dr_pt_try_drmach(hp); 30950Sstevel@tonic-gate 30960Sstevel@tonic-gate return (rv); 30970Sstevel@tonic-gate } 30980Sstevel@tonic-gate 30990Sstevel@tonic-gate /* 31000Sstevel@tonic-gate * Called at driver load time to determine the state and condition 31010Sstevel@tonic-gate * of an existing board in the system. 31020Sstevel@tonic-gate */ 31030Sstevel@tonic-gate static void 31040Sstevel@tonic-gate dr_board_discovery(dr_board_t *bp) 31050Sstevel@tonic-gate { 31060Sstevel@tonic-gate int i; 31070Sstevel@tonic-gate dr_devset_t devs_lost, devs_attached = 0; 31080Sstevel@tonic-gate dr_cpu_unit_t *cp; 31090Sstevel@tonic-gate dr_mem_unit_t *mp; 31100Sstevel@tonic-gate dr_io_unit_t *ip; 31110Sstevel@tonic-gate static fn_t f = "dr_board_discovery"; 31120Sstevel@tonic-gate 31130Sstevel@tonic-gate if (DR_DEVS_PRESENT(bp) == 0) { 31140Sstevel@tonic-gate PR_ALL("%s: board %d has no devices present\n", 31150Sstevel@tonic-gate f, bp->b_num); 31160Sstevel@tonic-gate return; 31170Sstevel@tonic-gate } 31180Sstevel@tonic-gate 31190Sstevel@tonic-gate /* 31200Sstevel@tonic-gate * Check for existence of cpus. 31210Sstevel@tonic-gate */ 31220Sstevel@tonic-gate for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) { 31230Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, i); 31240Sstevel@tonic-gate 31250Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&cp->sbc_cm)) 31260Sstevel@tonic-gate continue; 31270Sstevel@tonic-gate 31280Sstevel@tonic-gate if (dr_check_unit_attached(&cp->sbc_cm) >= 0) { 31290Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&cp->sbc_cm); 31300Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_CPU, i); 31310Sstevel@tonic-gate PR_ALL("%s: board %d, cpu-unit %d - attached\n", 31320Sstevel@tonic-gate f, bp->b_num, i); 31330Sstevel@tonic-gate } 31340Sstevel@tonic-gate dr_init_cpu_unit(cp); 31350Sstevel@tonic-gate } 31360Sstevel@tonic-gate 31370Sstevel@tonic-gate /* 31380Sstevel@tonic-gate * Check for existence of memory. 31390Sstevel@tonic-gate */ 31400Sstevel@tonic-gate for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) { 31410Sstevel@tonic-gate mp = dr_get_mem_unit(bp, i); 31420Sstevel@tonic-gate 31430Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&mp->sbm_cm)) 31440Sstevel@tonic-gate continue; 31450Sstevel@tonic-gate 31460Sstevel@tonic-gate if (dr_check_unit_attached(&mp->sbm_cm) >= 0) { 31470Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&mp->sbm_cm); 31480Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_MEM, i); 31490Sstevel@tonic-gate PR_ALL("%s: board %d, mem-unit %d - attached\n", 31500Sstevel@tonic-gate f, bp->b_num, i); 31510Sstevel@tonic-gate } 31520Sstevel@tonic-gate dr_init_mem_unit(mp); 31530Sstevel@tonic-gate } 31540Sstevel@tonic-gate 31550Sstevel@tonic-gate /* 31560Sstevel@tonic-gate * Check for i/o state. 31570Sstevel@tonic-gate */ 31580Sstevel@tonic-gate for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) { 31590Sstevel@tonic-gate ip = dr_get_io_unit(bp, i); 31600Sstevel@tonic-gate 31610Sstevel@tonic-gate if (!DR_DEV_IS_PRESENT(&ip->sbi_cm)) 31620Sstevel@tonic-gate continue; 31630Sstevel@tonic-gate 31640Sstevel@tonic-gate if (dr_check_unit_attached(&ip->sbi_cm) >= 0) { 31650Sstevel@tonic-gate /* 31660Sstevel@tonic-gate * Found it! 31670Sstevel@tonic-gate */ 31680Sstevel@tonic-gate DR_DEV_SET_ATTACHED(&ip->sbi_cm); 31690Sstevel@tonic-gate DEVSET_ADD(devs_attached, SBD_COMP_IO, i); 31700Sstevel@tonic-gate PR_ALL("%s: board %d, io-unit %d - attached\n", 31710Sstevel@tonic-gate f, bp->b_num, i); 31720Sstevel@tonic-gate } 31730Sstevel@tonic-gate dr_init_io_unit(ip); 31740Sstevel@tonic-gate } 31750Sstevel@tonic-gate 31760Sstevel@tonic-gate DR_DEVS_CONFIGURE(bp, devs_attached); 31770Sstevel@tonic-gate if (devs_attached && ((devs_lost = DR_DEVS_UNATTACHED(bp)) != 0)) { 31780Sstevel@tonic-gate int ut; 31790Sstevel@tonic-gate /* 31800Sstevel@tonic-gate * It is not legal on board discovery to have a 31810Sstevel@tonic-gate * board that is only partially attached. A board 31820Sstevel@tonic-gate * is either all attached or all connected. If a 31830Sstevel@tonic-gate * board has at least one attached device, then 31840Sstevel@tonic-gate * the the remaining devices, if any, must have 31850Sstevel@tonic-gate * been lost or disconnected. These devices can 31860Sstevel@tonic-gate * only be recovered by a full attach from scratch. 31870Sstevel@tonic-gate * Note that devices previously in the unreferenced 31880Sstevel@tonic-gate * state are subsequently lost until the next full 31890Sstevel@tonic-gate * attach. This is necessary since the driver unload 31900Sstevel@tonic-gate * that must have occurred would have wiped out the 31910Sstevel@tonic-gate * information necessary to re-configure the device 31920Sstevel@tonic-gate * back online, e.g. memlist. 31930Sstevel@tonic-gate */ 3194*1772Sjl139090 PR_ALL("%s: some devices LOST (0x%lx)...\n", f, devs_lost); 31950Sstevel@tonic-gate 31960Sstevel@tonic-gate for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) { 31970Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_CPU, ut)) 31980Sstevel@tonic-gate continue; 31990Sstevel@tonic-gate 32000Sstevel@tonic-gate cp = dr_get_cpu_unit(bp, ut); 32010Sstevel@tonic-gate dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY); 32020Sstevel@tonic-gate } 32030Sstevel@tonic-gate 32040Sstevel@tonic-gate for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) { 32050Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_MEM, ut)) 32060Sstevel@tonic-gate continue; 32070Sstevel@tonic-gate 32080Sstevel@tonic-gate mp = dr_get_mem_unit(bp, ut); 32090Sstevel@tonic-gate dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY); 32100Sstevel@tonic-gate } 32110Sstevel@tonic-gate 32120Sstevel@tonic-gate for (ut = 0; ut < MAX_IO_UNITS_PER_BOARD; ut++) { 32130Sstevel@tonic-gate if (!DEVSET_IN_SET(devs_lost, SBD_COMP_IO, ut)) 32140Sstevel@tonic-gate continue; 32150Sstevel@tonic-gate 32160Sstevel@tonic-gate ip = dr_get_io_unit(bp, ut); 32170Sstevel@tonic-gate dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY); 32180Sstevel@tonic-gate } 32190Sstevel@tonic-gate 32200Sstevel@tonic-gate DR_DEVS_DISCONNECT(bp, devs_lost); 32210Sstevel@tonic-gate } 32220Sstevel@tonic-gate } 32230Sstevel@tonic-gate 32240Sstevel@tonic-gate static int 32250Sstevel@tonic-gate dr_board_init(dr_board_t *bp, dev_info_t *dip, int bd) 32260Sstevel@tonic-gate { 32270Sstevel@tonic-gate sbd_error_t *err; 32280Sstevel@tonic-gate 32290Sstevel@tonic-gate mutex_init(&bp->b_lock, NULL, MUTEX_DRIVER, NULL); 32300Sstevel@tonic-gate mutex_init(&bp->b_slock, NULL, MUTEX_DRIVER, NULL); 32310Sstevel@tonic-gate cv_init(&bp->b_scv, NULL, CV_DRIVER, NULL); 32320Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 32330Sstevel@tonic-gate bp->b_ostate = SBD_STAT_UNCONFIGURED; 32340Sstevel@tonic-gate bp->b_cond = SBD_COND_UNKNOWN; 32350Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32360Sstevel@tonic-gate 32370Sstevel@tonic-gate (void) drmach_board_lookup(bd, &bp->b_id); 32380Sstevel@tonic-gate bp->b_num = bd; 32390Sstevel@tonic-gate bp->b_dip = dip; 32400Sstevel@tonic-gate 32410Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_CPU)] = GETSTRUCT(dr_dev_unit_t, 3242*1772Sjl139090 MAX_CPU_UNITS_PER_BOARD); 32430Sstevel@tonic-gate 32440Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_MEM)] = GETSTRUCT(dr_dev_unit_t, 3245*1772Sjl139090 MAX_MEM_UNITS_PER_BOARD); 32460Sstevel@tonic-gate 32470Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_IO)] = GETSTRUCT(dr_dev_unit_t, 3248*1772Sjl139090 MAX_IO_UNITS_PER_BOARD); 32490Sstevel@tonic-gate 32500Sstevel@tonic-gate /* 32510Sstevel@tonic-gate * Initialize the devlists 32520Sstevel@tonic-gate */ 32530Sstevel@tonic-gate err = dr_init_devlists(bp); 32540Sstevel@tonic-gate if (err) { 32550Sstevel@tonic-gate sbd_err_clear(&err); 32560Sstevel@tonic-gate dr_board_destroy(bp); 32570Sstevel@tonic-gate return (-1); 32580Sstevel@tonic-gate } else if (bp->b_ndev == 0) { 32590Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 32600Sstevel@tonic-gate } else { 32610Sstevel@tonic-gate /* 32620Sstevel@tonic-gate * Couldn't have made it down here without 32630Sstevel@tonic-gate * having found at least one device. 32640Sstevel@tonic-gate */ 32650Sstevel@tonic-gate ASSERT(DR_DEVS_PRESENT(bp) != 0); 32660Sstevel@tonic-gate /* 32670Sstevel@tonic-gate * Check the state of any possible devices on the 32680Sstevel@tonic-gate * board. 32690Sstevel@tonic-gate */ 32700Sstevel@tonic-gate dr_board_discovery(bp); 32710Sstevel@tonic-gate 32720Sstevel@tonic-gate bp->b_assigned = 1; 32730Sstevel@tonic-gate 32740Sstevel@tonic-gate if (DR_DEVS_UNATTACHED(bp) == 0) { 32750Sstevel@tonic-gate /* 32760Sstevel@tonic-gate * The board has no unattached devices, therefore 32770Sstevel@tonic-gate * by reason of insanity it must be configured! 32780Sstevel@tonic-gate */ 32790Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONFIGURED); 32800Sstevel@tonic-gate bp->b_ostate = SBD_STAT_CONFIGURED; 32810Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32820Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 32830Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32840Sstevel@tonic-gate } else if (DR_DEVS_ATTACHED(bp)) { 32850Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_PARTIAL); 32860Sstevel@tonic-gate bp->b_ostate = SBD_STAT_CONFIGURED; 32870Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32880Sstevel@tonic-gate bp->b_cond = SBD_COND_OK; 32890Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32900Sstevel@tonic-gate } else { 32910Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_CONNECTED); 32920Sstevel@tonic-gate bp->b_rstate = SBD_STAT_CONNECTED; 32930Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 32940Sstevel@tonic-gate } 32950Sstevel@tonic-gate } 32960Sstevel@tonic-gate 32970Sstevel@tonic-gate return (0); 32980Sstevel@tonic-gate } 32990Sstevel@tonic-gate 33000Sstevel@tonic-gate static void 33010Sstevel@tonic-gate dr_board_destroy(dr_board_t *bp) 33020Sstevel@tonic-gate { 33030Sstevel@tonic-gate PR_ALL("dr_board_destroy: num %d, path %s\n", 33040Sstevel@tonic-gate bp->b_num, bp->b_path); 33050Sstevel@tonic-gate 33060Sstevel@tonic-gate dr_board_transition(bp, DR_STATE_EMPTY); 33070Sstevel@tonic-gate bp->b_rstate = SBD_STAT_EMPTY; 33080Sstevel@tonic-gate (void) drv_getparm(TIME, (void *)&bp->b_time); 33090Sstevel@tonic-gate 33100Sstevel@tonic-gate /* 33110Sstevel@tonic-gate * Free up MEM unit structs. 33120Sstevel@tonic-gate */ 33130Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_MEM)], 3314*1772Sjl139090 dr_dev_unit_t, MAX_MEM_UNITS_PER_BOARD); 33150Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_MEM)] = NULL; 33160Sstevel@tonic-gate /* 33170Sstevel@tonic-gate * Free up CPU unit structs. 33180Sstevel@tonic-gate */ 33190Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_CPU)], 3320*1772Sjl139090 dr_dev_unit_t, MAX_CPU_UNITS_PER_BOARD); 33210Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_CPU)] = NULL; 33220Sstevel@tonic-gate /* 33230Sstevel@tonic-gate * Free up IO unit structs. 33240Sstevel@tonic-gate */ 33250Sstevel@tonic-gate FREESTRUCT(bp->b_dev[NIX(SBD_COMP_IO)], 3326*1772Sjl139090 dr_dev_unit_t, MAX_IO_UNITS_PER_BOARD); 33270Sstevel@tonic-gate bp->b_dev[NIX(SBD_COMP_IO)] = NULL; 33280Sstevel@tonic-gate 33290Sstevel@tonic-gate mutex_destroy(&bp->b_lock); 33300Sstevel@tonic-gate mutex_destroy(&bp->b_slock); 33310Sstevel@tonic-gate cv_destroy(&bp->b_scv); 33320Sstevel@tonic-gate } 33330Sstevel@tonic-gate 33340Sstevel@tonic-gate void 33350Sstevel@tonic-gate dr_lock_status(dr_board_t *bp) 33360Sstevel@tonic-gate { 33370Sstevel@tonic-gate mutex_enter(&bp->b_slock); 33380Sstevel@tonic-gate while (bp->b_sflags & DR_BSLOCK) 33390Sstevel@tonic-gate cv_wait(&bp->b_scv, &bp->b_slock); 33400Sstevel@tonic-gate bp->b_sflags |= DR_BSLOCK; 33410Sstevel@tonic-gate mutex_exit(&bp->b_slock); 33420Sstevel@tonic-gate } 33430Sstevel@tonic-gate 33440Sstevel@tonic-gate void 33450Sstevel@tonic-gate dr_unlock_status(dr_board_t *bp) 33460Sstevel@tonic-gate { 33470Sstevel@tonic-gate mutex_enter(&bp->b_slock); 33480Sstevel@tonic-gate bp->b_sflags &= ~DR_BSLOCK; 33490Sstevel@tonic-gate cv_signal(&bp->b_scv); 33500Sstevel@tonic-gate mutex_exit(&bp->b_slock); 33510Sstevel@tonic-gate } 33520Sstevel@tonic-gate 33530Sstevel@tonic-gate /* 33540Sstevel@tonic-gate * Extract flags passed via ioctl. 33550Sstevel@tonic-gate */ 33560Sstevel@tonic-gate int 33570Sstevel@tonic-gate dr_cmd_flags(dr_handle_t *hp) 33580Sstevel@tonic-gate { 33590Sstevel@tonic-gate return (hp->h_sbdcmd.cmd_cm.c_flags); 33600Sstevel@tonic-gate } 3361