2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stddef.h>
2N/A#include <string.h>
2N/A#include <strings.h>
2N/A#include <alloca.h>
2N/A#include <libnvpair.h>
2N/A
2N/A#include <scsi/libses.h>
2N/A#include <scsi/libses_plugin.h>
2N/A#include <scsi/plugins/ses/framework/libses.h>
2N/A#include <scsi/plugins/ses/vendor/sun.h>
2N/A#include <scsi/plugins/ses/vendor/sun_impl.h>
2N/A#include <scsi/plugins/ses/framework/ses2.h>
2N/A#include <scsi/plugins/ses/framework/ses2_impl.h>
2N/A
2N/A#include "../../../../../../lib/libfru/libnvfru/nvfru.h"
2N/A
2N/Aint
2N/Asun_fruid_parse_common(sun_fru_descr_impl_t *sfdip, nvlist_t *nvl)
2N/A{
2N/A int nverr;
2N/A
2N/A SES_NV_ADD(boolean_value, nverr, nvl,
2N/A LIBSES_PROP_FRU, sfdip-> sfdi_fru);
2N/A SES_NV_ADD(uint64, nverr, nvl,
2N/A LIBSES_PROP_PHYS_PARENT, sfdip->sfdi_parent_element_index);
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Given an nvlist of properties and an array of property handlers, invoke the
2N/A * appropriate handler for all supported properties.
2N/A */
2N/Aint
2N/Asun_setprop(ses_plugin_t *sp, ses_node_t *np,
2N/A const ses2_ctl_prop_t *ctlprops, nvlist_t *props)
2N/A{
2N/A const ses2_ctl_prop_t *cpp;
2N/A nvpair_t *nvp, *next;
2N/A
2N/A for (nvp = nvlist_next_nvpair(props, NULL); nvp != NULL;
2N/A nvp = next) {
2N/A next = nvlist_next_nvpair(props, nvp);
2N/A for (cpp = ctlprops; cpp->scp_name != NULL; cpp++)
2N/A if (strcmp(cpp->scp_name, nvpair_name(nvp)) == 0)
2N/A break;
2N/A if (cpp->scp_name == NULL)
2N/A continue;
2N/A
2N/A if (cpp->scp_setprop(sp, np, cpp->scp_num, nvp) != 0)
2N/A return (-1);
2N/A
2N/A (void) nvlist_remove(props, nvpair_name(nvp),
2N/A nvpair_type(nvp));
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Asun_ctl_common_setprop(ses_plugin_t *sp, ses_node_t *np, ses2_diag_page_t page,
2N/A nvpair_t *nvp)
2N/A{
2N/A ses2_cmn_elem_ctl_impl_t *eip;
2N/A const char *name;
2N/A boolean_t v;
2N/A
2N/A ASSERT(page == SES2_DIAGPAGE_ENCLOSURE_CTL_STATUS);
2N/A
2N/A if ((eip = ses_plugin_ctlpage_lookup(sp, ses_node_snapshot(np),
2N/A page, 0, np, B_FALSE)) == NULL)
2N/A return (-1);
2N/A
2N/A name = nvpair_name(nvp);
2N/A (void) nvpair_value_boolean_value(nvp, &v);
2N/A
2N/A if (strcmp(name, SES_PROP_SWAP) == 0)
2N/A eip->seci_rst_swap = !v;
2N/A else if (strcmp(name, SES_PROP_DISABLED) == 0)
2N/A eip->seci_disable = v;
2N/A else if (strcmp(name, SES_PROP_PRDFAIL) == 0)
2N/A eip->seci_prdfail = v;
2N/A else
2N/A ses_panic("Bad property %s", name);
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Astatic int
2N/Asun_node_parse(ses_plugin_t *sp, ses_node_t *np)
2N/A{
2N/A switch (ses_node_type(np)) {
2N/A case SES_NODE_ENCLOSURE:
2N/A return (sun_fill_enclosure_node(sp, np));
2N/A
2N/A case SES_NODE_AGGREGATE:
2N/A case SES_NODE_ELEMENT:
2N/A return (sun_fill_element_node(sp, np));
2N/A
2N/A default:
2N/A return (0);
2N/A }
2N/A}
2N/A
2N/Astatic int
2N/Asun_node_ctl(ses_plugin_t *sp, ses_node_t *np, const char *op,
2N/A nvlist_t *nvl)
2N/A{
2N/A switch (ses_node_type(np)) {
2N/A case SES_NODE_ENCLOSURE:
2N/A break;
2N/A
2N/A case SES_NODE_AGGREGATE:
2N/A case SES_NODE_ELEMENT:
2N/A return (sun_element_ctl(sp, np, op, nvl));
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Asun_node_type_known(ses_plugin_t *sp, ses_node_t *np)
2N/A{
2N/A
2N/A nvlist_t *props = ses_node_props(np);
2N/A uint64_t type;
2N/A
2N/A VERIFY(nvlist_lookup_uint64(props, SES_PROP_ELEMENT_TYPE,
2N/A &type) == 0);
2N/A
2N/A if ((type != SES_ET_SUNW_FANMODULE) &&
2N/A (type != SES_ET_SUNW_POWERBOARD) &&
2N/A (type != SES_ET_SUNW_POWERMODULE) &&
2N/A (type != SES_ET_SUNW_FANBOARD)) {
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/A_ses_init(ses_plugin_t *sp)
2N/A{
2N/A ses_plugin_config_t config = {
2N/A .spc_pages = sun_pages,
2N/A .spc_node_parse = sun_node_parse,
2N/A .spc_node_ctl = sun_node_ctl,
2N/A .spc_node_type_known = sun_node_type_known
2N/A };
2N/A
2N/A return (ses_plugin_register(sp, LIBSES_PLUGIN_VERSION,
2N/A &config) != 0);
2N/A}