a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER START
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The contents of this file are subject to the terms of the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Common Development and Distribution License (the "License").
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You may not use this file except in compliance with the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * See the License for the specific language governing permissions
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * and limitations under the License.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * When distributing Covered Code, include this CDDL HEADER in each
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If applicable, add the following below this CDDL HEADER, with the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * fields enclosed by brackets "[]" replaced with your own identifying
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * information: Portions Copyright [yyyy] [name of copyright owner]
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CDDL HEADER END
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Use is subject to license terms.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2010, Intel Corporation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All rights reserved.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * PIM-DR layer of DR driver. Provides interface between user
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * level applications and the PSM-DR layer.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuextern int nulldev();
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuextern int nodev();
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* DEBUG */
8682d1ef2a0960ed5a9f05b9448eaa3e68ac931fRichard Lowestatic int dr_dev_type_to_nt(char *);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * NOTE: state_str, nt_str and SBD_CMD_STR are only used in a debug
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * kernel. They are, however, referenced during both debug and non-debug
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "PARTIAL", "CONFIGURED", "RELEASE", "UNREFERENCED",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#define DR_GET_BOARD_DEVUNIT(sb, ut, un) (&((sb)->b_dev[DEVSET_NIX(ut)][un]))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* for the DR*INTERNAL_ERROR macros. see sys/dr.h. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* struct for drmach device name to sbd_comp_type_t mapping */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liutypedef struct {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* struct to map starfire device attributes - name:sbd_comp_type_t */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* last s_devtype must be NULL, s_nodetype must be SBD_COMP_UNKNOWN */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Per instance soft-state structure.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * dr Global data elements
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_softstate_t *softsp; /* pointer to initialize soft state */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Table of known passthru commands.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liuint dr_modunload_okay = 0; /* set to non-zero to allow unload */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * State transition table. States valid transitions for "board" state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Recall that non-zero return value terminates operation, however
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the herrno value is what really indicates an error , if any.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Translate DR CMD to index into dr_state_transition.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu switch (c) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu case SBD_CMD_CONNECT: return (0);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu default: return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* connected */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* unconfigured */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* connected */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* unconfigured */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* partial */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* configured */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* partial */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* configured */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* release */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* unreferenced */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* empty */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu { 0, 0 }, /* occupied */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Global R/W lock to synchronize access across
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * multiple boards. Users wanting multi-board access
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * must grab WRITE lock, others must grab READ lock.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Head of the boardlist used as a reference point for
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * locating board structs.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * TODO: eliminate dr_boardlist
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * DR support functions.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic dr_devset_t dr_dev2devset(sbd_comp_id_t *cid);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_check_unit_attached(dr_common_unit_t *dp);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic sbd_error_t *dr_init_devlists(dr_board_t *bp);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_board_init(dr_board_t *bp, dev_info_t *dip, int bd);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic void dr_board_transition(dr_board_t *bp, dr_state_t st);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * DR driver (DDI) entry points.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_close(dev_t dev, int flag, int otyp, cred_t *cred_p);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liustatic int dr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * DR command processing operations.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Autoconfiguration data structures
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu D_NEW | D_MP | D_MTSAFE, /* compatibility flags */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu 0, /* dev ref count */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "Dynamic Reconfiguration",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Driver entry points.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If you need to support multiple nodes (instances), then
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * whatever the maximum number of supported nodes is would
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * need to passed as the third parameter to ddi_soft_state_init().
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Alternative would be to dynamically fini and re-init the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * soft state structure each time a node is attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*ARGSUSED1*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_open(dev_t *dev, int flag, int otyp, cred_t *cred_p)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Don't open unless we've attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp = ddi_get_soft_state(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* initialize each array element */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* destroy elements initialized thus far */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* TODO: should this be another errno val ? */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bp = &softsp->boards[DR_MINOR2BNUM(getminor(*dev))];
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * prevent opening of a dyn-ap for a board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * that does not exist
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (drmach_board_lookup(bp->b_num, &bp->b_id) != 0)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_close(dev_t dev, int flag, int otyp, cred_t *cred_p)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Enable/disable DR features.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/*ARGSUSED3*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp = ddi_get_soft_state(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_WARN, "dr%d: module not yet attached", instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* get and initialize storage for new handle */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd command into handle */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* translate canonical name to component type */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_dev_type_to_nt(hp->h_sbdcmd.cmd_cm.c_id.c_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* determine scope of operation */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_devset = dr_dev2devset(&hp->h_sbdcmd.cmd_cm.c_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* no locks needed for these commands */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If we're dealing with memory at all, then we have
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * to keep the "exclusive" global lock held. This is
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * necessary since we will probably need to look at
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * multiple board structs. Otherwise, we only have
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * to deal with the board in question and so can drop
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the global lock to "shared".
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rv = DEVSET_IN_SET(hp->h_devset, SBD_COMP_MEM, DEVSET_ANYUNIT);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* undo locking, if any, done before dr_pre_op */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Board changed state. Log a sysevent. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Fall through */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu FREESTRUCT(hp->h_opts.copts, char, hp->h_opts.size);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rv = ddi_soft_state_zalloc(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_WARN, "dr%d: failed to alloc soft-state",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* initialize softstate structure */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp = ddi_get_soft_state(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu mutex_init(&softsp->i_lock, NULL, MUTEX_DRIVER, NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* allocate board array (aka boardlist) */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp->boards = GETSTRUCT(dr_board_t, MAX_BOARDS);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* TODO: eliminate dr_boardlist */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* initialize each array element */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * initialized board attachment point path
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * (relative to pseudo) in a form immediately
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * reusable as an cfgadm command argument.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * TODO: clean this up
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu while (*p != '\0') {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Announce the node's presence.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Init registered unsafe devs.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rv2 = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "unsupported-io-drivers", &dr_unsafe_devs.devnames,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*NOTREACHED*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp = ddi_get_soft_state(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* TODO: eliminate dr_boardlist */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* remove all minor nodes */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu FREESTRUCT(softsp->boards, dr_board_t, MAX_BOARDS);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*NOTREACHED*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu softsp = ddi_get_soft_state(dr_g.softsp, instance);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * DR operations.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_copyin((void *)hp->h_iap, (void *)&scmd32,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: (32bit) failed to copyin "
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "sbdcmd-struct", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scp->cmd_cm.c_id.c_type = scmd32.cmd_cm.c_id.c_type;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scp->cmd_cm.c_id.c_unit = scmd32.cmd_cm.c_id.c_unit;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scp->cmd_cm.c_opts = (caddr_t)(uintptr_t)scmd32.cmd_cm.c_opts;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scp->cmd_stat.s_nbytes = scmd32.cmd_stat.s_nbytes;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* _MULTI_DATAMODEL */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: failed to copyin sbdcmd-struct", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_opts.copts = GETSTRUCT(char, scp->cmd_cm.c_len + 1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu cmn_err(CE_WARN, "%s: failed to copyin options", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scmd32.cmd_cm.c_id.c_type = scp->cmd_cm.c_id.c_type;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scmd32.cmd_cm.c_id.c_unit = scp->cmd_cm.c_id.c_unit;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu scmd32.cmd_cm.c_opts = (caddr32_t)(uintptr_t)scp->cmd_cm.c_opts;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_copyout((void *)&scmd32, (void *)hp->h_iap,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: (32bit) failed to copyout "
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "sbdcmd-struct", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* _MULTI_DATAMODEL */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: failed to copyout sbdcmd-struct", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_model_convert_from(hp->h_mode & FMODELS) == DDI_MODEL_ILP32) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: (32bit) failed to copyout", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* _MULTI_DATAMODEL */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: failed to copyout", f);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * pre-op entry point must sbd_err_set_c(), if needed.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Return value of non-zero indicates failure.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_err = drmach_pre_op(cmd, bp->b_id, &hp->h_opts, &devset);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check for valid state transitions.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu state_err = dr_check_transition(bp, &devset, transp, cmd);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Invalidate device.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else if (state_err != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * State transition is not a valid one.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: invalid state %s(%d) for cmd %s(%d)\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s (cmd = %s)...\n", f, SBD_CMD_STR(cmd));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu err = drmach_post_op(cmd, bp->b_id, &hp->h_opts, rv);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* errors should have been caught by now */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: unknown command (%d)",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_err = drmach_board_assign(bp->b_num, &bp->b_id);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out status during unassign.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Not doing cv_wait_sig here as starfire SSP software
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * ignores unassign failure and removes board from
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * domain mask causing system panic.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * TODO: Change cv_wait to cv_wait_sig when SSP software
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * handles unassign failure.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * clear drmachid_t handle; not valid after board unassign
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_err = drmach_board_test(bp->b_id, &hp->h_opts,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Create and populate the component nodes for a board. Assumes that the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * devlists for the board have been initialized.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Make nodes for the individual components on the board.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * First we need to initialize memory unit data structures of board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * structure.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Initialize cpu unit data structures.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Initialize io unit data structures.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Only do work if called to operate on an entire board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * which doesn't already have components present.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Board already has devices present.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: devices already present (" DEVSET_FMT_STR ")\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_err = drmach_board_connect(bp->b_id, &hp->h_opts);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_op_err(CE_WARN, hp, ESBD_EMPTY_BD, bp->b_path);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /*NOTREACHED*/
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Only devices which are present, but
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * unattached can be disconnected.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_op_err(CE_IGNORE, hp, ESBD_EMPTY_BD, bp->b_path);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out status during disconnect.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_err = drmach_board_disconnect(bp->b_id, &hp->h_opts);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (hp->h_err && hp->h_err->e_code == EX86_WALK_DEPENDENCY) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Other boards have dependency on this board. No device nodes
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * have been destroyed so keep current board status.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Update per-device state transitions.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * For certain errors, drmach_board_disconnect will mark
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the board as unusable; in these cases the devtree must
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * be purged so that status calls will succeed.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * This implementation checks for discrete error codes -
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * someday, the i/f to drmach_board_disconnect should be
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * changed to avoid the e_code testing.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Once all the components on a board have been disconnect
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the board's state can transition to disconnected and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * we can allow the deprobe to take place.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (hp->h_err == NULL && DR_DEVS_PRESENT(bp) == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check if a particular device is a valid target of the current
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * operation. Return 1 if it is a valid target, and 0 otherwise.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_is_target(dr_dev_unit_t *dp, int present_only, uint_t uset)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* check if the user requested this device */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If the present_only flag is set, a valid target
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * must be present but not attached. Otherwise, it
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * must be both present and attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* sanity check */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_make_list(dr_handle_t *hp, sbd_comp_type_t type, int present_only,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* catch this in debug kernels */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* allocate list storage. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* record length of storage in first element */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* get bit array signifying which units are to be involved */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Adjust the loop count for CPU devices since all cores
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * in a CMP will be examined in a single iteration.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* populate list */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (wp = list, unum = 0; unum < nunits; unum++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* further processing is only required for CPUs */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Add any additional cores from the current CPU
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * device. This is to ensure that all the cores
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * are grouped together in the device list, and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * consequently sequenced together during the actual
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * operation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (core = 1; core < MAX_CORES_PER_CMP; core++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* calculate number of units in list, return result and list pointer */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_clean_up(dr_handle_t *hp, dr_common_unit_t **list, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * move first encountered unit error to handle if handle
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * does not yet have a recorded error.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu while (n++ < devnum) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* free remaining unit errors */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu while (n++ < devnum) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* free list */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_walk(dr_handle_t *hp, sbd_comp_type_t type, int present_only,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu int (*pre_op)(dr_handle_t *, dr_common_unit_t **, int),
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu int (*post_op)(dr_handle_t *, dr_common_unit_t **, int),
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu void (*board_op)(dr_handle_t *, dr_common_unit_t **, int))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_dev_make_list(hp, type, present_only, &devlist, &devnum);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv == 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (n = 0; n < devnum; n++)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_noop(dr_handle_t *hp, dr_common_unit_t **devlist, int devnum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All devices finally attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Only some devices are fully attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All devices finally attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv >= 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv >= 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If the entire board was released and all components
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * unreferenced then transfer it to the UNREFERENCED state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* called by dr_release_done [below] and dr_release_mem_done [dr_mem.c] */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_release_done(dr_handle_t *hp, dr_common_unit_t *cp)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* get board pointer & sanity check */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Transfer the device which just completed its release
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * to the UNREFERENCED state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If we're not already in the RELEASE state for this
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * board and we now have released all that were previously
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * attached, then transfer the board to the RELEASE state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (DR_DEVS_RELEASED(bp) == DR_DEVS_UNREFERENCED(bp))) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_release_mem(dr_handle_t *hp, dr_common_unit_t *dv)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv >= 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rv >= 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* else, b_busy will be cleared in dr_detach_update_state() */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < devnum; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Device is still attached probably due
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * to an error. Need to keep track of it.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DR_DEVS_PRESENT(bp) == DR_DEVS_UNATTACHED(bp)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * All devices are finally detached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Some devices remain attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((hp->h_devset & DR_DEVS_UNATTACHED(bp)) == hp->h_devset)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out status during IO unconfig.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Only devices which have been "released" are
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * subject to cancellation.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Nothing to do for CPUs or IO other than change back
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * their state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&ip->sbi_cm, DR_STATE_CONFIGURED);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: unreleasing devset (0x%x)\n", f, (uint_t)devset);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If the board no longer has any released devices
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * than transfer it back to the CONFIG/PARTIAL state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *)&hp->h_bd->b_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* _MULTI_DATAMODEL */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Block out disconnect, unassign, IO unconfigure and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * devinfo branch creation during status.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (hp->h_sbdcmd.cmd_cm.c_id.c_type == SBD_COMP_NONE) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Calculate the maximum number of components possible
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * for a board. This number will be used to size the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * status scratch buffer used by board and component
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * status functions.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * This buffer may differ in size from what is provided
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * by the plugin, since the known component set on the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * board may change between the plugin's GETNCM call, and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the status call. Sizing will be adjusted to the plugin's
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * receptacle buffer at copyout time.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * In the case of c_type == SBD_COMP_NONE, and
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * SBD_FLAG_ALLCMP not specified, only the board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * info is to be returned, no components.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu pnstat = (pbsz - sizeof (sbd_stat_t)) / sizeof (sbd_dev_stat_t);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * s_nbytes describes the size of the preallocated user
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * buffer into which the application is execting to
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * receive the sbd_stat_t and sbd_dev_stat_t structures.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * More buffer space is required for the 64bit to 32bit
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * conversion of data structures.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Since one sbd_dev_stat_t is included in the sbd_stat_t,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * increment the plugin's nstat count.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dstatp = (sbd_stat_t *)(void *)GETSTRUCT(char, sz);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Detect transitions between empty and disconnected.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (!pstat.empty && (bp->b_rstate == SBD_STAT_EMPTY))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu else if (pstat.empty && (bp->b_rstate == SBD_STAT_DISCONNECTED))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dstatp->s_assigned = bp->b_assigned = pstat.assigned;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bcopy(&pstat.type[0], &dstatp->s_type[0], SBD_TYPE_LEN);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bcopy(&pstat.info[0], &dstatp->s_info[0], SBD_MAX_INFO);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * No device chosen.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((nstat = dr_cpu_status(hp, devset, devstatp)) > 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((nstat = dr_mem_status(hp, devset, devstatp)) > 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT))
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((nstat = dr_io_status(hp, devset, devstatp)) > 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Due to a possible change in number of components between
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the time of plugin's GETNCM call and now, there may be
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * more or less components than the plugin's buffer can
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * hold. Adjust s_nstat accordingly.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dstatp->s_nstat = dstatp->s_nstat > pnstat ? pnstat : dstatp->s_nstat;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* Alignment Paranoia */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* paranoia: detect buffer overrun */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_cm_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_cpu_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_mem_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_io_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (j = 0; j < SBD_MAX_UNSAFE; j++)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* copy sbd_cmp_stat_t structure members */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu hp->h_sbdcmd.cmd_stat.s_statp, pbsz, mode) != 0) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: failed to copyout status "
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#endif /* _MULTI_DATAMODEL */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (ddi_copyout((void *)dstatp, hp->h_sbdcmd.cmd_stat.s_statp,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: failed to copyout status for board %d",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (hp->h_sbdcmd.cmd_cm.c_id.c_type != SBD_COMP_NONE)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Handle CPUs first to deal with possible CMP
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * devices. If the CPU is a CMP, we need to only
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * increment ncm once even if there are multiple
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * cores for that CMP present in the devset.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CMP_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* eliminate the CPU information from the devset */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu devset &= ~(DEVSET(SBD_COMP_CMP, DEVSET_ANYUNIT));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < (sizeof (dr_devset_t) * 8); i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu/* TODO: eliminate dr_boardlist */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_get_dev_unit(dr_board_t *bp, sbd_comp_type_t nt, int unit_num)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(unit_num >= 0 && unit_num < MAX_CPU_UNITS_PER_BOARD);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(unit_num >= 0 && unit_num < MAX_MEM_UNITS_PER_BOARD);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ASSERT(unit_num >= 0 && unit_num < MAX_IO_UNITS_PER_BOARD);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_get_common_unit(dr_board_t *bp, sbd_comp_type_t nt, int unum)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: COMP_NONE devset = " DEVSET_FMT_STR "\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((unit > MAX_CPU_UNITS_PER_BOARD) || (unit < 0)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: invalid cpu unit# = %d",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Generate a devset that includes all the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * cores of a CMP device. If this is not a
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * CMP, the extra cores will be eliminated
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * later since they are not present. This is
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * also true for CMP devices that do not have
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * all cores active.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((unit > MAX_MEM_UNITS_PER_BOARD) || (unit < 0)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: invalid mem unit# = %d",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if ((unit > MAX_IO_UNITS_PER_BOARD) || (unit < 0)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu "%s: invalid io unit# = %d",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Converts a dynamic attachment point name to a SBD_COMP_* type.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Returns SDB_COMP_UNKNOWN if name is not recognized.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Converts a SBD_COMP_* type to a dynamic attachment point name.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Return NULL if SBD_COMP_ type is not recognized.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; dr_devattr[i].s_nodetype != SBD_COMP_UNKNOWN; i++)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * State transition policy is that if there is some component for which
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the state transition is valid, then let it through. The exception is
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * SBD_CMD_DISCONNECT. On disconnect, the state transition must be valid
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * for ALL components.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Returns the state that is in error, if any.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_check_transition(dr_board_t *bp, dr_devset_t *devsetp,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_CPU, DEVSET_ANYUNIT)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_MEM, DEVSET_ANYUNIT)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (DEVSET_IN_SET(devset, SBD_COMP_IO, DEVSET_ANYUNIT)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: requested devset = 0x%x, final devset = 0x%x\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * If there are some remaining components for which
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * this state transition is valid, then allow them
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * through, otherwise if none are left then return
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the state error. The exception is SBD_CMD_DISCONNECT.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * On disconnect, the state transition must be valid for ALL
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * components.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_device_transition(dr_common_unit_t *cp, dr_state_t st)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (cp->sbdev_bp->b_ostate != SBD_STAT_CONFIGURED) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) drv_getparm(TIME, (void *) &cp->sbdev_time);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_op_err(int ce, dr_handle_t *hp, int code, char *fmt, ...)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * A callback routine. Called from the drmach layer as a result of
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * call to drmach_board_find_devices from dr_init_devlists.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_dev_found(void *data, const char *name, int unum, drmachid_t id)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s (board = %d, name = %s, unum = %d, id = %p)...\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * this should not happen. When it does, it indicates
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * a missmatch in devices supported by the drmach layer
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * vs devices supported by this layer.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* sanity check */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* render dynamic attachment point path of this unit */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* sanity check */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * This routine builds the board's devlist and initializes
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the common portion of the unit data structures.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Note: because the common portion is considered
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * uninitialized, the dr_get_*_unit() routines can not
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Clear out old entries, if any.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* find devices on this board */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Return the unit number of the respective drmachid if
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * it's found to be attached.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check if base address is in phys_install.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu } else if (!yes)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: unexpected nodetype(%d) for id 0x%p\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * See if drmach recognizes the passthru command. DRMACH expects the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * id to identify the thing to which the command is being applied. Using
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * nonsense SBD terms, that information has been perversely encoded in the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * c_id member of the sbd_cmd_t structure. This logic reads those tea
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * leaves, finds the associated drmach id, then calls drmach to process
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the passthru command.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu sbd_comp_id_t *comp_id = &hp->h_sbdcmd.cmd_cm.c_id;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_op_err(CE_IGNORE, hp, ESBD_INVAL, comp_id->c_name);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu /* pt command applied to dynamic attachment point */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (cmd = 0; cmd < (sizeof (pt_arr) / sizeof (pt_arr[0])); cmd++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu found = (strncmp(pt_arr[cmd].pt_name, copts, len) == 0);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Called at driver load time to determine the state and condition
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * of an existing board in the system.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check for existence of cpus.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_CPU_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check for existence of memory.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_MEM_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check for i/o state.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (i = 0; i < MAX_IO_UNITS_PER_BOARD; i++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (devs_attached && ((devs_lost = DR_DEVS_UNATTACHED(bp)) != 0)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * It is not legal on board discovery to have a
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * board that is only partially attached. A board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * is either all attached or all connected. If a
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * board has at least one attached device, then
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * the the remaining devices, if any, must have
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * been lost or disconnected. These devices can
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * only be recovered by a full attach from scratch.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Note that devices previously in the unreferenced
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * state are subsequently lost until the next full
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * attach. This is necessary since the driver unload
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * that must have occurred would have wiped out the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * information necessary to re-configure the device
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * back online, e.g. memlist.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu PR_ALL("%s: some devices LOST (" DEVSET_FMT_STR ")...\n",
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (ut = 0; ut < MAX_CPU_UNITS_PER_BOARD; ut++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&cp->sbc_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu for (ut = 0; ut < MAX_MEM_UNITS_PER_BOARD; ut++) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&mp->sbm_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu dr_device_transition(&ip->sbi_cm, DR_STATE_EMPTY);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liudr_board_init(dr_board_t *bp, dev_info_t *dip, int bd)
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu mutex_init(&bp->b_lock, NULL, MUTEX_DRIVER, NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu mutex_init(&bp->b_slock, NULL, MUTEX_DRIVER, NULL);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bp->b_dev[DEVSET_NIX(SBD_COMP_CPU)] = GETSTRUCT(dr_dev_unit_t,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bp->b_dev[DEVSET_NIX(SBD_COMP_MEM)] = GETSTRUCT(dr_dev_unit_t,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu bp->b_dev[DEVSET_NIX(SBD_COMP_IO)] = GETSTRUCT(dr_dev_unit_t,
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Initialize the devlists
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu return (-1);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Couldn't have made it down here without
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * having found at least one device.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Check the state of any possible devices on the
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * The board has no unattached devices, therefore
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * by reason of insanity it must be configured!
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Free up MEM unit structs.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Free up CPU unit structs.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Free up IO unit structs.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Reset the board structure to its initial state, otherwise it will
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * cause trouble on the next call to dr_board_init() for the same board.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * dr_board_init() may be called multiple times for the same board
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * if DR driver fails to initialize some boards.
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Extract flags passed via ioctl.