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) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * Create a generic topology node.
2N/A */
2N/A#include <sys/types.h>
2N/A#include <strings.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <fm/topo_mod.h>
2N/A#include <fm/topo_hc.h>
2N/A#include <x86pi_impl.h>
2N/A
2N/A#define _ENUM_NAME "enum_generic"
2N/A#define _FAC_PROV "fac_prov_ipmi"
2N/A
2N/A/*
2N/A * Create a generic topo node based on the hcfmri strcuture passed in.
2N/A */
2N/Aint
2N/Ax86pi_enum_generic(topo_mod_t *mod, x86pi_hcfmri_t *hcfmri,
2N/A tnode_t *t_bindparent, tnode_t *t_fmriparent, tnode_t **t_node, int flag)
2N/A{
2N/A int rv;
2N/A int err;
2N/A nvlist_t *out;
2N/A nvlist_t *fmri;
2N/A nvlist_t *auth;
2N/A
2N/A topo_mod_dprintf(mod, "%s adding entry for type (%s)\n",
2N/A _ENUM_NAME, hcfmri->hc_name);
2N/A
2N/A if (t_bindparent == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s called with NULL parent for type %s\n",
2N/A _ENUM_NAME, hcfmri->hc_name);
2N/A return (-1);
2N/A }
2N/A
2N/A /* Create the FMRI for this node */
2N/A auth = topo_mod_auth(mod, t_bindparent);
2N/A fmri = topo_mod_hcfmri(mod, t_fmriparent, FM_HC_SCHEME_VERSION,
2N/A hcfmri->hc_name, hcfmri->instance, NULL, auth,
2N/A hcfmri->part_number, hcfmri->version, hcfmri->serial_number);
2N/A
2N/A nvlist_free(auth);
2N/A
2N/A if (fmri == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s failed to create %s fmri : %s\n", _ENUM_NAME,
2N/A hcfmri->hc_name, topo_strerror(topo_mod_errno(mod)));
2N/A return (-1);
2N/A }
2N/A
2N/A rv = topo_node_range_create(mod, t_bindparent, hcfmri->hc_name, 0, 4);
2N/A if (rv != 0 && topo_mod_errno(mod) != EMOD_NODE_DUP) {
2N/A topo_mod_dprintf(mod, "%s range create failed for node %s\n",
2N/A _ENUM_NAME, hcfmri->hc_name);
2N/A }
2N/A
2N/A /* Bind this node to the parent */
2N/A *t_node = x86pi_node_bind(mod, t_bindparent, hcfmri, fmri, flag);
2N/A nvlist_free(fmri);
2N/A if (*t_node == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s failed to bind %s node instance %d: %s\n",
2N/A _ENUM_NAME, hcfmri->hc_name, hcfmri->instance,
2N/A topo_strerror(topo_mod_errno(mod)));
2N/A return (-1);
2N/A }
2N/A
2N/A /* call IPMI facility provider to register fac methods */
2N/A if (topo_mod_load(mod, _FAC_PROV, TOPO_VERSION) == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: Failed to load %s module: %s\n", _ENUM_NAME, _FAC_PROV,
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A rv = topo_mod_enumerate(mod, *t_node, _FAC_PROV, _FAC_PROV, 0, 0, NULL);
2N/A if (rv != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: %s failed: %s\n", _ENUM_NAME, _FAC_PROV,
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A /* invoke fac_prov_ipmi_enum method */
2N/A if (topo_method_supported(*t_node, TOPO_METH_FAC_ENUM, 0)) {
2N/A if (topo_method_invoke(*t_node, TOPO_METH_FAC_ENUM, 0, NULL,
2N/A &out, &err) != 0) {
2N/A /* log the error and drive on */
2N/A topo_mod_dprintf(mod,
2N/A "%s: TOPO_METH_FAC_ENUM failed\n", _ENUM_NAME);
2N/A } else {
2N/A fac_done = 1;
2N/A }
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s added (%s) node\n", _ENUM_NAME,
2N/A topo_node_name(*t_node));
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/Atnode_t *
2N/Ax86pi_node_bind(topo_mod_t *mod, tnode_t *t_parent, x86pi_hcfmri_t *hcfmri,
2N/A nvlist_t *fmri, int flag)
2N/A{
2N/A int result;
2N/A tnode_t *t_node;
2N/A char *f = "x86pi_node_bind";
2N/A
2N/A if (t_parent == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: NULL parent for %s node instance %d\n",
2N/A f, hcfmri->hc_name, hcfmri->instance);
2N/A return (NULL);
2N/A }
2N/A
2N/A /* Bind this node to the parent */
2N/A t_node = topo_node_bind(mod, t_parent, hcfmri->hc_name,
2N/A hcfmri->instance, fmri);
2N/A if (t_node == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "%s: failed to bind %s node instance %d: %s\n",
2N/A f, hcfmri->hc_name, (uint32_t)hcfmri->instance,
2N/A topo_strerror(topo_mod_errno(mod)));
2N/A return (NULL);
2N/A }
2N/A topo_mod_dprintf(mod, "%s: bound %s node instance %d type %s\n",
2N/A f, hcfmri->hc_name, hcfmri->instance, hcfmri->hc_name);
2N/A
2N/A /*
2N/A * We have bound the node. Now decorate it with an appropriate
2N/A * FRU and label (which may be inherited from the parent).
2N/A */
2N/A result = x86pi_set_frufmri(mod, hcfmri, t_parent, t_node, flag);
2N/A if (result != 0) {
2N/A /*
2N/A * Though we have failed to set the FRU FMRI we still continue.
2N/A * The module errno is set by the called routine, so we report
2N/A * the problem and move on.
2N/A */
2N/A topo_mod_dprintf(mod,
2N/A "%s: failed to set FRU FMRI for %s node\n",
2N/A f, hcfmri->hc_name);
2N/A }
2N/A
2N/A result = x86pi_set_label(mod, hcfmri->location, hcfmri->hc_name,
2N/A t_node);
2N/A if (result != 0) {
2N/A /*
2N/A * Though we have failed to set the label, we still continue.
2N/A * The module errno is set by the called routine, so we report
2N/A * the problem and move on.
2N/A */
2N/A topo_mod_dprintf(mod, "%s: no label for %s node\n",
2N/A f, hcfmri->hc_name);
2N/A }
2N/A
2N/A result = x86pi_set_auth(mod, hcfmri, t_parent, t_node);
2N/A if (result != 0) {
2N/A /*
2N/A * Though we have failed to set the authority, we still
2N/A * continue. The module errno is set by the called routine, so
2N/A * we report the problem and move on.
2N/A */
2N/A topo_mod_dprintf(mod,
2N/A "%s: no authority information for %s node\n",
2N/A f, hcfmri->hc_name);
2N/A }
2N/A
2N/A result = x86pi_set_system(mod, t_node);
2N/A if (result != 0) {
2N/A /*
2N/A * Though we have failed to set the system group, we still
2N/A * continue. The module errno is set by the called routine, so
2N/A * we report the problem and move on.
2N/A */
2N/A topo_mod_dprintf(mod,
2N/A "%s: no system information for %s node\n",
2N/A f, hcfmri->hc_name);
2N/A }
2N/A
2N/A return (t_node);
2N/A}