908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * CDDL HEADER START
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The contents of this file are subject to the terms of the
908f1e1388f616898b4e515d343c0414f2a6472esd * Common Development and Distribution License (the "License").
908f1e1388f616898b4e515d343c0414f2a6472esd * You may not use this file except in compliance with the License.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
908f1e1388f616898b4e515d343c0414f2a6472esd * or http://www.opensolaris.org/os/licensing.
908f1e1388f616898b4e515d343c0414f2a6472esd * See the License for the specific language governing permissions
908f1e1388f616898b4e515d343c0414f2a6472esd * and limitations under the License.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * When distributing Covered Code, include this CDDL HEADER in each
908f1e1388f616898b4e515d343c0414f2a6472esd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
908f1e1388f616898b4e515d343c0414f2a6472esd * If applicable, add the following below this CDDL HEADER, with the
908f1e1388f616898b4e515d343c0414f2a6472esd * fields enclosed by brackets "[]" replaced with your own identifying
908f1e1388f616898b4e515d343c0414f2a6472esd * information: Portions Copyright [yyyy] [name of copyright owner]
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * CDDL HEADER END
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Subroutines used by various components of the Sun4v PI enumerator
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd#include <sys/types.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <sys/systeminfo.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <sys/utsname.h>
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier#include <string.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <strings.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <sys/fm/protocol.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <fm/topo_mod.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <fm/topo_hc.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <sys/mdesc.h>
908f1e1388f616898b4e515d343c0414f2a6472esd#include <libnvpair.h>
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd#include "pi_impl.h"
908f1e1388f616898b4e515d343c0414f2a6472esd
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/* max pci path = 256 */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier#define MAX_PATH_DEPTH (MAXPATHLEN / 256)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/* max pci path + child + minor */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier#define MAX_DIPATH_DEPTH (MAX_PATH_DEPTH + 2)
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
908f1e1388f616898b4e515d343c0414f2a6472esdstatic const topo_pgroup_info_t sys_pgroup = {
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PGROUP_SYSTEM,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_STABILITY_PRIVATE,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_STABILITY_PRIVATE,
908f1e1388f616898b4e515d343c0414f2a6472esd 1
908f1e1388f616898b4e515d343c0414f2a6472esd};
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esdstatic const topo_pgroup_info_t auth_pgroup = {
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_STABILITY_PRIVATE,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_STABILITY_PRIVATE,
908f1e1388f616898b4e515d343c0414f2a6472esd 1
908f1e1388f616898b4e515d343c0414f2a6472esd};
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Search the PRI for MDE nodes using md_scan_dag. Using this routine
908f1e1388f616898b4e515d343c0414f2a6472esd * consolodates similar searches used in a few places within the sun4vpi
908f1e1388f616898b4e515d343c0414f2a6472esd * enumerator.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The routine returns the number of nodes found, or -1. If the node array
908f1e1388f616898b4e515d343c0414f2a6472esd * is non-NULL on return, then it must be freed:
908f1e1388f616898b4e515d343c0414f2a6472esd * topo_mod_free(mod, nodes, nsize);
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_find_mdenodes(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_start,
908f1e1388f616898b4e515d343c0414f2a6472esd char *type_str, char *arc_str, mde_cookie_t **nodes, size_t *nsize)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int total_mdenodes;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd mde_str_cookie_t start_cookie;
908f1e1388f616898b4e515d343c0414f2a6472esd mde_str_cookie_t arc_cookie;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Prepare to scan the PRI using the start string and given arc */
908f1e1388f616898b4e515d343c0414f2a6472esd total_mdenodes = md_node_count(mdp);
908f1e1388f616898b4e515d343c0414f2a6472esd start_cookie = md_find_name(mdp, type_str);
908f1e1388f616898b4e515d343c0414f2a6472esd arc_cookie = md_find_name(mdp, arc_str);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Allocate an array to hold the results of the scan */
908f1e1388f616898b4e515d343c0414f2a6472esd *nsize = sizeof (mde_cookie_t) * total_mdenodes;
908f1e1388f616898b4e515d343c0414f2a6472esd *nodes = topo_mod_zalloc(mod, *nsize);
908f1e1388f616898b4e515d343c0414f2a6472esd if (*nodes == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* We have no memory. Set an error code and return failure */
908f1e1388f616898b4e515d343c0414f2a6472esd *nsize = 0;
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, EMOD_NOMEM);
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_scan_dag(mdp, mde_start, start_cookie, arc_cookie, *nodes);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result <= 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* No nodes found. Free the node array before returning */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_free(mod, *nodes, *nsize);
908f1e1388f616898b4e515d343c0414f2a6472esd *nodes = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd *nsize = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (result);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Determine if this node should be skipped by finding the topo-skip property.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_skip_node(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd uint64_t skip;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (mod == NULL || mdp == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * These parameters are required. Tell the caller to skip
908f1e1388f616898b4e515d343c0414f2a6472esd * all nodes.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd return (1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd skip = 0; /* do not skip by default */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_val(mdp, mde_node, MD_STR_TOPO_SKIP, &skip);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * There is no topo-skip property. Assume we are not skipping
908f1e1388f616898b4e515d343c0414f2a6472esd * the mde node.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd skip = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * If skip is present and non-zero we want to skip this node. We
908f1e1388f616898b4e515d343c0414f2a6472esd * return 1 to indicate this.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd if (skip != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Build a device path without device names (PRI like) from a devinfo
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * node. Return the PRI like path.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The string must be freed with topo_mod_strfree()
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierchar *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierpi_get_dipath(topo_mod_t *mod, di_node_t dnode)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier{
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int i, j, rv;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int depth = 0;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier char *bus_addr[MAX_DIPATH_DEPTH] = { NULL };
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier char *dev_path[MAX_DIPATH_DEPTH] = { NULL };
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier char *path = NULL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier size_t path_len = 0;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* loop through collecting bus addresses */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier do {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* stop at '/' */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strcmp(di_devfs_path(dnode), "/") == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier break;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (depth < MAX_DIPATH_DEPTH) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bus_addr[depth] = topo_mod_strdup(mod,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_bus_addr(dnode));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier ++depth;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier } else {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod, "pi_get_dipath: path too "
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier "long (%d)\n", depth);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (NULL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier } while ((dnode = di_parent_node(dnode)) != DI_NODE_NIL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* prepend '/@' to each bus address */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (i = (depth - 1), j = 0; i >= 0; --i, j++) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int len = strlen(bus_addr[i]) + strlen("/@") + 1;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier path_len += len;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier dev_path[j] = (char *)topo_mod_alloc(mod, len);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier rv = snprintf(dev_path[j], len, "/@%s", bus_addr[i]);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (rv < 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (NULL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Build the path from the bus addresses.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier path_len -= (depth - 1); /* leave room for one null char */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier path = (char *)topo_mod_alloc(mod, path_len);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier path = strcpy(path, dev_path[0]);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (i = 1; i < depth; i++) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier path = strncat(path, dev_path[i], strlen(dev_path[i]) + 1);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (i = 0; i < depth; i++) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (bus_addr[i] != NULL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_strfree(mod, bus_addr[i]);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (dev_path[i] != NULL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_strfree(mod, dev_path[i]);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod, "pi_get_dipath: path (%s)\n", path);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (path);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye/*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * Get the product serial number (the ID as far as the topo authority is
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * concerned) either from the current node, if it is of type 'product', or
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * search for a product node in the PRI.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye *
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * The string must be freed with topo_mod_strfree()
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Yechar *
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Yepi_get_productsn(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye{
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye int result;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye int idx;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye int num_nodes;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye char *id = NULL;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye char *type;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye size_t size;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye mde_cookie_t *nodes = NULL;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_get_productsn: enter\n");
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = md_get_prop_str(mdp, mde_node, MD_STR_TYPE, &type);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result == 0 && strcmp(type, MD_STR_PRODUCT) == 0) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * This is a product node. We need only search for the serial
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * number property on this node to return the ID.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = md_get_prop_str(mdp, mde_node, MD_STR_SERIAL_NUMBER,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye &id);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0 || id == NULL || strlen(id) == 0)
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye return (NULL);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_get_productsn: product-sn = %s\n",
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye id);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye return (topo_mod_strdup(mod, id));
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * Search the PRI for nodes of type MD_STR_COMPONENT and find the
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * first element with type of MD_STR_PRODUCT. This node
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * will contain the MD_STR_SERIAL_NUMBER property to use as the
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * product-sn.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye num_nodes = pi_find_mdenodes(mod, mdp, MDE_INVAL_ELEM_COOKIE,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye MD_STR_COMPONENT, MD_STR_FWD, &nodes, &size);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (num_nodes <= 0 || nodes == NULL) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* We did not find any component nodes */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye return (NULL);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_get_productsn: found %d %s nodes\n",
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye num_nodes, MD_STR_COMPONENT);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye idx = 0;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye while (id == NULL && idx < num_nodes) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = md_get_prop_str(mdp, nodes[idx], MD_STR_TYPE, &type);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result == 0 && strcmp(type, MD_STR_PRODUCT) == 0) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * This is a product node. Get the serial number
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * property from the node.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = md_get_prop_str(mdp, nodes[idx],
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye MD_STR_SERIAL_NUMBER, &id);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0)
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_get_productsn: "
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye "failed to read %s from node_0x%llx\n",
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye MD_STR_SERIAL_NUMBER,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye (uint64_t)nodes[idx]);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* Search the next node, if necessary */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye idx++;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_free(mod, nodes, size);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* Everything is freed up and it's time to return the product-sn */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0 || id == NULL || strlen(id) == 0) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye return (NULL);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_get_productsn: product-sn %s\n", id);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye return (topo_mod_strdup(mod, id));
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye}
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Get the chassis serial number (the ID as far as the topo authority is
908f1e1388f616898b4e515d343c0414f2a6472esd * concerned) either from the current node, if it is of type 'chassis', or
908f1e1388f616898b4e515d343c0414f2a6472esd * search for a chassis node in the PRI.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_chassisid(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int idx;
908f1e1388f616898b4e515d343c0414f2a6472esd int num_nodes;
908f1e1388f616898b4e515d343c0414f2a6472esd char *id = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *hc_name = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd size_t chassis_size;
908f1e1388f616898b4e515d343c0414f2a6472esd mde_cookie_t *chassis_nodes = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_chassis: enter\n");
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd hc_name = pi_get_topo_hc_name(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd if (hc_name != NULL && strcmp(hc_name, MD_STR_CHASSIS) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * This is a chassis node. We need only search for the serial
908f1e1388f616898b4e515d343c0414f2a6472esd * number property on this node to return the ID.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_SERIAL_NUMBER,
908f1e1388f616898b4e515d343c0414f2a6472esd &id);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || id == NULL || strlen(id) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_chassis: chassis-id = %s\n", id);
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, id));
908f1e1388f616898b4e515d343c0414f2a6472esd }
021ceb9857f712f245edda92c7eb82f0a3a83acbTom Pothier if (hc_name != NULL) {
021ceb9857f712f245edda92c7eb82f0a3a83acbTom Pothier topo_mod_strfree(mod, hc_name);
021ceb9857f712f245edda92c7eb82f0a3a83acbTom Pothier }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Search the PRI for nodes of type MD_STR_COMPONENT and find the
908f1e1388f616898b4e515d343c0414f2a6472esd * first element with topo-hc-type of MD_STR_CHASSIS. This node
908f1e1388f616898b4e515d343c0414f2a6472esd * will contain the MD_STR_SERIAL_NUMBER property to use as the
908f1e1388f616898b4e515d343c0414f2a6472esd * chassis-id.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd num_nodes = pi_find_mdenodes(mod, mdp, MDE_INVAL_ELEM_COOKIE,
908f1e1388f616898b4e515d343c0414f2a6472esd MD_STR_COMPONENT, MD_STR_FWD, &chassis_nodes, &chassis_size);
908f1e1388f616898b4e515d343c0414f2a6472esd if (num_nodes <= 0 || chassis_nodes == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* We did not find any chassis nodes */
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_chassisid: found %d %s nodes\n",
908f1e1388f616898b4e515d343c0414f2a6472esd num_nodes, MD_STR_COMPONENT);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd idx = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd while (id == NULL && idx < num_nodes) {
908f1e1388f616898b4e515d343c0414f2a6472esd hc_name = pi_get_topo_hc_name(mod, mdp, chassis_nodes[idx]);
908f1e1388f616898b4e515d343c0414f2a6472esd if (hc_name != NULL && strcmp(hc_name, MD_STR_CHASSIS) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * This is a chassis node. Get the serial number
908f1e1388f616898b4e515d343c0414f2a6472esd * property from the node.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, chassis_nodes[idx],
908f1e1388f616898b4e515d343c0414f2a6472esd MD_STR_SERIAL_NUMBER, &id);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_chassisid: "
908f1e1388f616898b4e515d343c0414f2a6472esd "failed to read %s from node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd MD_STR_SERIAL_NUMBER,
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)chassis_nodes[idx]);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Search the next node, if necessary */
908f1e1388f616898b4e515d343c0414f2a6472esd idx++;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_free(mod, chassis_nodes, chassis_size);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Everything is freed up and it's time to return the platform-id */
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || id == NULL || strlen(id) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_chassis: chassis-id %s\n", id);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, id));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Determine if the node is a FRU by checking for the existance and non-zero
908f1e1388f616898b4e515d343c0414f2a6472esd * value of the 'fru' property on the mde node.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_fru(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, int *is_fru)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd uint64_t fru;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (mod == NULL || mdp == NULL || is_fru == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd fru = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd *is_fru = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_val(mdp, mde_node, MD_STR_FRU, &fru);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* The node is not a FRU. */
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd if (fru != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd *is_fru = 1;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Get the id property value from the given PRI node
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_instance(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
908f1e1388f616898b4e515d343c0414f2a6472esd topo_instance_t *ip)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd uint64_t id;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd id = 0;
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_val(mdp, mde_node, MD_STR_ID, &id);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * There is no id property.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "node_0x%llx has no id property\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd *ip = id;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * If the given MDE node is a FRU return the 'nac' property, if it exists,
908f1e1388f616898b4e515d343c0414f2a6472esd * to use as the label.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_label(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int is_fru;
908f1e1388f616898b4e515d343c0414f2a6472esd char *lp = NULL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier char *hc_name = pi_get_topo_hc_name(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The disk enumerator will set the "bay" node as a FRU and
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * expect the label from the PRI. The "fru" property can not
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * be set because hostconfig has no way to set the S/N, P/N,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * etc.. in the PRI.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strncmp(hc_name, BAY, strlen(BAY)) != 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier result = pi_get_fru(mod, mdp, mde_node, &is_fru);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (result != 0 || is_fru == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* This node is not a FRU. It has no label */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_strfree(mod, hc_name);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (NULL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
908f1e1388f616898b4e515d343c0414f2a6472esd }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_strfree(mod, hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * The node is a FRU. Get the NAC name to use as a label.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_NAC, &lp);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || lp == NULL || strlen(lp) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* No NAC label. Return NULL */
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Return a copy of the label */
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, lp));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Return the "lun" property.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierint
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierpi_get_lun(topo_mod_t *mod, di_node_t node)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier{
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int lun;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int *buf;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier unsigned char *chbuf;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop_t di_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_t dpath = DI_PATH_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_t di_path_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for pathinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((dpath = di_path_phci_next_path(node, dpath)) != DI_PATH_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((di_path_prop =
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_next(dpath, di_path_prop)) != DI_PROP_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strcmp("lun",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_name(di_path_prop)) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier (void) di_path_prop_ints(di_path_prop, &buf);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bcopy(buf, &lun, sizeof (int));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for devinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (di_prop = di_prop_next(node, DI_PROP_NIL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop != DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop = di_prop_next(node, di_prop)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strncmp("lun", di_prop_name(di_prop),
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier strlen(di_prop_name(di_prop))) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop_bytes(di_prop, &chbuf) < sizeof (uint_t)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier continue;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bcopy(chbuf, &lun, sizeof (uint_t));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop == DI_PROP_NIL && (dpath == DI_PATH_NIL ||
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop == DI_PROP_NIL)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (-1);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierfound:
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod, "pi_get_lun: lun = (%d)\n", lun);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (lun);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Return the complete part number string to the caller. The complete part
908f1e1388f616898b4e515d343c0414f2a6472esd * number is made up of the part number attribute concatenated with the dash
908f1e1388f616898b4e515d343c0414f2a6472esd * number attribute of the mde node.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_part(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd size_t bufsize;
908f1e1388f616898b4e515d343c0414f2a6472esd char *buf = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *part = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *dash = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_PART_NUMBER, &part);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd part = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_DASH_NUMBER, &dash);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd dash = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd bufsize = 1 + (part ? strlen(part) : 0) + (dash ? strlen(dash) : 0);
908f1e1388f616898b4e515d343c0414f2a6472esd if (bufsize == 1) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Construct the part number from the part and dash values */
908f1e1388f616898b4e515d343c0414f2a6472esd buf = topo_mod_alloc(mod, bufsize);
908f1e1388f616898b4e515d343c0414f2a6472esd if (buf != NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd (void) snprintf(buf, bufsize, "%s%s", (part ? part : ""),
908f1e1388f616898b4e515d343c0414f2a6472esd (dash ? dash : ""));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (buf);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier/*
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * Return the path string to the caller.
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier *
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * The string must be freed with topo_mod_strfree()
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothierchar *
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothierpi_get_path(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier{
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier int result;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier int i = 0;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier size_t max_addrs;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier size_t path_len = 0;
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier size_t buf_len;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *propbuf = NULL;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *buf = NULL;
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier char *buffree;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *path = NULL;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *token;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *dev_addr[MAX_PATH_DEPTH] = { NULL };
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *dev_path[MAX_PATH_DEPTH] = { NULL };
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier char *lastp;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier /*
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * Get the path property from PRI; should look something
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * like "/@600/@0".
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier result = md_get_prop_str(mdp, mde_node, MD_STR_PATH, &propbuf);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if (result != 0 || propbuf == NULL || strlen(propbuf) == 0) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_dprintf(mod, "pi_get_path: failed to get path\n");
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier return (NULL);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier buf_len = strlen(propbuf) + 1;
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier buf = topo_mod_alloc(mod, buf_len);
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier if (buf == NULL) {
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier topo_mod_dprintf(mod, "pi_get_path: no memory\n");
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier return (NULL);
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier }
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier buffree = buf; /* strtok_r is destructive */
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier (void) strcpy(buf, propbuf);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier /*
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * Grab the address(es) from the path property.
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if ((token = strtok_r(buf, "/@", &lastp)) != NULL) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier dev_addr[i] = topo_mod_strdup(mod, token);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier while ((token = strtok_r(NULL, "/@", &lastp)) != NULL) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if (++i < MAX_PATH_DEPTH) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier dev_addr[i] = topo_mod_strdup(mod, token);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier } else {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_dprintf(mod, "pi_get_path: path "
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier "too long (%d)\n", i);
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier topo_mod_free(mod, buffree, buf_len);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier return (NULL);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier } else {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_dprintf(mod, "pi_get_path: path wrong\n");
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier topo_mod_free(mod, buffree, buf_len);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier return (NULL);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier max_addrs = ++i;
71cff6baf8966128bb0c13508d1fe6e3b91a317bTom Pothier topo_mod_free(mod, buffree, buf_len);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier /*
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * Construct the path to look something like "/pci@600/pci@0".
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier for (i = 0; i < max_addrs; i++) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier int len = strlen(dev_addr[i]) + strlen("/pci@") + 1;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier path_len += len;
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier dev_path[i] = (char *)topo_mod_alloc(mod, len);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier result = snprintf(dev_path[i], len, "/pci@%s", dev_addr[i]);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if (result < 0) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier return (NULL);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier path_len -= (i - 1); /* leave room for one null char */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier path = (char *)topo_mod_alloc(mod, path_len);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier path = strcpy(path, dev_path[0]);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier /* put the parts together */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier for (i = 1; i < max_addrs; i++) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier path = strncat(path, dev_path[i], strlen(dev_path[i]) + 1);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier /*
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier * Cleanup
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier */
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier for (i = 0; i < max_addrs; i++) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if (dev_addr[i] != NULL) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_free(mod, dev_addr[i],
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier strlen(dev_addr[i]) + 1);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier if (dev_path[i] != NULL) {
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_free(mod, dev_path[i],
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier strlen(dev_path[i]) + 1);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier }
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier topo_mod_dprintf(mod, "pi_get_path: path = (%s)\n", path);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier return (path);
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier}
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
73a0bd151c1115bf39cc2caa30c7cbfdd86361c1Tom Pothier
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Get the product ID from the 'platform' node in the PRI
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_productid(topo_mod_t *mod, md_t *mdp)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd char *id = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd size_t platform_size;
908f1e1388f616898b4e515d343c0414f2a6472esd mde_cookie_t *platform_nodes = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_product: enter\n");
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Search the PRI for nodes of type MD_STR_PLATFORM, which contains
908f1e1388f616898b4e515d343c0414f2a6472esd * the product-id in it's MD_STR_NAME property.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = pi_find_mdenodes(mod, mdp, MDE_INVAL_ELEM_COOKIE,
908f1e1388f616898b4e515d343c0414f2a6472esd MD_STR_PLATFORM, MD_STR_FWD, &platform_nodes, &platform_size);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result <= 0 || platform_nodes == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* We did not find any platform nodes */
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_productid: found %d platform nodes\n",
908f1e1388f616898b4e515d343c0414f2a6472esd result);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * There should only be 1 platform node, so we will always
908f1e1388f616898b4e515d343c0414f2a6472esd * use the first if we find any at all.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, platform_nodes[0], MD_STR_NAME, &id);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_free(mod, platform_nodes, platform_size);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Everything is freed up and it's time to return the platform-id */
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || id == NULL || strlen(id) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_product: returning %s\n", id);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, id));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * If the phy pointer is NULL just return the number of 'phy_number' properties
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * from the PRI; otherwise pass the 'phy_number' property values back to the
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * caller.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The caller is responsible for managing allocated memory.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierint
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierpi_get_priphy(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, uint8_t *phyp)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier{
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int result;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier uint8_t *phy_num;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int nphy;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier result = md_get_prop_data(mdp, mde_node, MD_STR_PHY_NUMBER,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier &phy_num, &nphy);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (result != 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* no phy_number property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier "node_0x%llx has no phy_number property\n",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier (uint64_t)mde_node);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (-1);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (phyp != NULL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bcopy(phy_num, phyp, nphy);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (nphy);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Return "phy-num" devinfo/pathinfo property.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierint
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierpi_get_phynum(topo_mod_t *mod, di_node_t node)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier{
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int phy;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier int *buf;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier unsigned char *chbuf;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop_t di_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_t dpath = DI_PATH_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_t di_path_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for pathinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((dpath = di_path_phci_next_path(node, dpath)) != DI_PATH_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((di_path_prop =
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_next(dpath, di_path_prop)) != DI_PROP_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strcmp("phy-num",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_name(di_path_prop)) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier (void) di_path_prop_ints(di_path_prop, &buf);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bcopy(buf, &phy, sizeof (int));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for devinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (di_prop = di_prop_next(node, DI_PROP_NIL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop != DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop = di_prop_next(node, di_prop)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strncmp("phy-num", di_prop_name(di_prop),
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier strlen("phy-num")) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop_bytes(di_prop, &chbuf) < sizeof (uint_t)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier continue;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier bcopy(chbuf, &phy, sizeof (uint_t));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop == DI_PROP_NIL && (dpath == DI_PATH_NIL ||
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop == DI_PROP_NIL)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (-1);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierfound:
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod, "pi_get_phynum: phy = %d\n", phy);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (phy);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Return the revision string to the caller.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_revision(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd char *rp = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_REVISION_NUMBER, &rp);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || rp == NULL || strlen(rp) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, rp));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Return the serial number string to the caller.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_serial(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd uint64_t sn;
908f1e1388f616898b4e515d343c0414f2a6472esd char *sp = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char buf[MAXNAMELEN];
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_SERIAL_NUMBER, &sp);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || sp == NULL || strlen(sp) == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Is this a uint64_t type serial number? */
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_val(mdp, mde_node, MD_STR_SERIAL_NUMBER,
908f1e1388f616898b4e515d343c0414f2a6472esd &sn);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* No. We have failed to find a serial number */
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_serial: node_0x%llx numeric "
908f1e1388f616898b4e515d343c0414f2a6472esd "serial number %llx\n", (uint64_t)mde_node, sn);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Convert the acquired value to a string */
908f1e1388f616898b4e515d343c0414f2a6472esd result = snprintf(buf, sizeof (buf), "%llu", sn);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result < 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd sp = buf;
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_serial: node_0x%llx = %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node, (sp == NULL ? "NULL" : sp));
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, sp));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Get the server hostname (the ID as far as the topo authority is
908f1e1388f616898b4e515d343c0414f2a6472esd * concerned) from sysinfo and return a copy to the caller.
908f1e1388f616898b4e515d343c0414f2a6472esd *
908f1e1388f616898b4e515d343c0414f2a6472esd * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_serverid(topo_mod_t *mod)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd char hostname[MAXNAMELEN];
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_serverid: enter\n");
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = sysinfo(SI_HOSTNAME, hostname, sizeof (hostname));
908f1e1388f616898b4e515d343c0414f2a6472esd /* Everything is freed up and it's time to return the platform-id */
908f1e1388f616898b4e515d343c0414f2a6472esd if (result == -1) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_get_serverid: hostname = %s\n", hostname);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, hostname));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Return the "target-port" property.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The string must be freed with topo_mod_strfree()
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierchar *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierpi_get_target_port(topo_mod_t *mod, di_node_t node)
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier{
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier char *tport;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop_t di_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_t dpath = DI_PATH_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_t di_path_prop = DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for pathinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((dpath = di_path_phci_next_path(node, dpath)) != DI_PATH_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier while ((di_path_prop =
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_next(dpath, di_path_prop)) != DI_PROP_NIL) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strcmp("target-port",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop_name(di_path_prop)) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier (void) di_path_prop_strings(di_path_prop,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier &tport);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /* look for devinfo property */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier for (di_prop = di_prop_next(node, DI_PROP_NIL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop != DI_PROP_NIL;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_prop = di_prop_next(node, di_prop)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strcmp("target-port", di_prop_name(di_prop)) == 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop_strings(di_prop, &tport) < 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier continue;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier goto found;
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (di_prop == DI_PROP_NIL && (dpath == DI_PATH_NIL ||
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier di_path_prop == DI_PROP_NIL)) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (NULL);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothierfound:
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod, "pi_get_target_port: 'target-port' = (%s)\n",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier tport);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier return (topo_mod_strdup(mod, tport));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier/*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Get the hc scheme name for the given node.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The string must be freed with topo_mod_strfree()
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdchar *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_get_topo_hc_name(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd char *hc_name;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Request the hc name from the node.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd hc_name = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd result = md_get_prop_str(mdp, mde_node, MD_STR_TOPO_HC_NAME, &hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || hc_name == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod,
908f1e1388f616898b4e515d343c0414f2a6472esd "failed to get property %s from node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd MD_STR_TOPO_HC_NAME, (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Return a copy of the type string */
908f1e1388f616898b4e515d343c0414f2a6472esd return (topo_mod_strdup(mod, hc_name));
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Calculate the authority information for a node. Inherit the data if
908f1e1388f616898b4e515d343c0414f2a6472esd * possible, but always create an appropriate property group.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_set_auth(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
908f1e1388f616898b4e515d343c0414f2a6472esd tnode_t *t_parent, tnode_t *t_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int err;
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_t *auth;
908f1e1388f616898b4e515d343c0414f2a6472esd char *val = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *prod = NULL;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye char *psn = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *csn = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd char *server = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (mod == NULL || mdp == NULL || t_parent == NULL || t_node == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_pgroup_create(t_node, &auth_pgroup, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We failed to create the property group and it was not
908f1e1388f616898b4e515d343c0414f2a6472esd * already defined. Set the err code and return failure.
908f1e1388f616898b4e515d343c0414f2a6472esd */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Get the authority information already available from the parent */
908f1e1388f616898b4e515d343c0414f2a6472esd auth = topo_mod_auth(mod, t_parent);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Set the authority data, inheriting it if possible, but creating it
908f1e1388f616898b4e515d343c0414f2a6472esd * if necessary.
908f1e1388f616898b4e515d343c0414f2a6472esd */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* product-id */
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_PRODUCT, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd val = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd result = nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT,
908f1e1388f616898b4e515d343c0414f2a6472esd &val);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || val == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * No product information in the parent node or auth
908f1e1388f616898b4e515d343c0414f2a6472esd * list. Find the product information in the PRI.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd prod = pi_get_productid(mod, mdp);
908f1e1388f616898b4e515d343c0414f2a6472esd if (prod == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: product "
908f1e1388f616898b4e515d343c0414f2a6472esd "name not found for node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd } else {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Dup the string. If we cannot find it in the auth
908f1e1388f616898b4e515d343c0414f2a6472esd * nvlist we will need to free it, so this lets us
908f1e1388f616898b4e515d343c0414f2a6472esd * have a single code path.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd prod = topo_mod_strdup(mod, val);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We continue even if the product information is not available
908f1e1388f616898b4e515d343c0414f2a6472esd * to enumerate as much as possible.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd if (prod != NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod,
908f1e1388f616898b4e515d343c0414f2a6472esd &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "set property %s (%d) : %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_CHASSIS, err,
908f1e1388f616898b4e515d343c0414f2a6472esd topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, prod);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* product-sn */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye FM_FMRI_AUTH_PRODUCT_SN, &err);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0 && err != ETOPO_PROP_DEFD) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye val = NULL;
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye &val);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0 || val == NULL) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * No product-sn information in the parent node or auth
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * list. Find the product-sn information in the PRI.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye psn = pi_get_productsn(mod, mdp, mde_node);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (psn == NULL) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_set_auth: psn "
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye "name not found for node_0x%llx\n",
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye (uint64_t)mde_node);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye } else {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * Dup the string. If we cannot find it in the auth
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * nvlist we will need to free it, so this lets us
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * have a single code path.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye psn = topo_mod_strdup(mod, val);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /*
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * We continue even if the product information is not available
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye * to enumerate as much as possible.
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye */
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (psn != NULL) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye &err);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye if (result != 0) {
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_dprintf(mod, "pi_set_auth: failed to "
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye "set property %s (%d) : %s\n",
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye FM_FMRI_AUTH_PRODUCT_SN, err,
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_strerror(err));
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye topo_mod_strfree(mod, psn);
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye }
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* chassis-id */
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_CHASSIS, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd val = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd result = nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS,
908f1e1388f616898b4e515d343c0414f2a6472esd &val);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || val == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * No product information in the parent node or auth
908f1e1388f616898b4e515d343c0414f2a6472esd * list. Find the product information in the PRI.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd csn = pi_get_chassisid(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd if (csn == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: csn "
908f1e1388f616898b4e515d343c0414f2a6472esd "name not found for node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd } else {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Dup the string. If we cannot find it in the auth
908f1e1388f616898b4e515d343c0414f2a6472esd * nvlist we will need to free it, so this lets us
908f1e1388f616898b4e515d343c0414f2a6472esd * have a single code path.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd csn = topo_mod_strdup(mod, val);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We continue even if the product information is not available
908f1e1388f616898b4e515d343c0414f2a6472esd * to enumerate as much as possible.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd if (csn != NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_CHASSIS, TOPO_PROP_IMMUTABLE, csn,
908f1e1388f616898b4e515d343c0414f2a6472esd &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "set property %s (%d) : %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_CHASSIS, err,
908f1e1388f616898b4e515d343c0414f2a6472esd topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, csn);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye /* server-id */
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_inherit(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_SERVER, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd val = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd result = nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER,
908f1e1388f616898b4e515d343c0414f2a6472esd &val);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || val == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * No product information in the parent node or auth
908f1e1388f616898b4e515d343c0414f2a6472esd * list. Find the product information in the PRI.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd server = pi_get_serverid(mod);
908f1e1388f616898b4e515d343c0414f2a6472esd if (server == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: server "
908f1e1388f616898b4e515d343c0414f2a6472esd "name not found for node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd } else {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Dup the string. If we cannot find it in the auth
908f1e1388f616898b4e515d343c0414f2a6472esd * nvlist we will need to free it, so this lets us
908f1e1388f616898b4e515d343c0414f2a6472esd * have a single code path.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd server = topo_mod_strdup(mod, val);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We continue even if the product information is not available
908f1e1388f616898b4e515d343c0414f2a6472esd * to enumerate as much as possible.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd if (server != NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_set_string(t_node, FM_FMRI_AUTHORITY,
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_SERVER, TOPO_PROP_IMMUTABLE, server,
908f1e1388f616898b4e515d343c0414f2a6472esd &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "set property %s (%d) : %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd FM_FMRI_AUTH_SERVER, err,
908f1e1388f616898b4e515d343c0414f2a6472esd topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, server);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_free(auth);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Calculate a generic FRU for the given node. If the node is not a FRU,
908f1e1388f616898b4e515d343c0414f2a6472esd * then inherit the FRU data from the nodes parent.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_set_frufmri(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
908f1e1388f616898b4e515d343c0414f2a6472esd const char *name, topo_instance_t inst, tnode_t *t_parent, tnode_t *t_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int err;
908f1e1388f616898b4e515d343c0414f2a6472esd int is_fru;
908f1e1388f616898b4e515d343c0414f2a6472esd char *part;
908f1e1388f616898b4e515d343c0414f2a6472esd char *rev;
908f1e1388f616898b4e515d343c0414f2a6472esd char *serial;
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_t *auth = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_t *frufmri = NULL;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (t_node == NULL || mod == NULL || mdp == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Determine if this node is a FRU
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd result = pi_get_fru(mod, mdp, mde_node, &is_fru);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 || is_fru == 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* This node is not a FRU. Inherit from parent and return */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_node_fru_set(t_node, NULL, 0, &result);
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * This node is a FRU. Create an FMRI.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd part = pi_get_part(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd rev = pi_get_revision(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd serial = pi_get_serial(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd auth = topo_mod_auth(mod, t_parent);
908f1e1388f616898b4e515d343c0414f2a6472esd frufmri = topo_mod_hcfmri(mod, t_parent, FM_HC_SCHEME_VERSION, name,
908f1e1388f616898b4e515d343c0414f2a6472esd inst, NULL, auth, part, rev, serial);
908f1e1388f616898b4e515d343c0414f2a6472esd if (frufmri == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "failed to create FRU: %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd topo_strerror(topo_mod_errno(mod)));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_free(auth);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, part);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, rev);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, serial);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Set the FRU, whether NULL or not */
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_node_fru_set(t_node, frufmri, 0, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_free(frufmri);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (result);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_set_label(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, tnode_t *t_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int err;
908f1e1388f616898b4e515d343c0414f2a6472esd char *label;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (mod == NULL || mdp == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Get the label, if any, from the mde node and apply it as the label
908f1e1388f616898b4e515d343c0414f2a6472esd * for this topology node. Note that a NULL label will inherit the
908f1e1388f616898b4e515d343c0414f2a6472esd * label from topology node's parent.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd label = pi_get_label(mod, mdp, mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_node_label_set(t_node, label, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_strfree(mod, label);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_label: failed with label %s "
908f1e1388f616898b4e515d343c0414f2a6472esd "on node_0x%llx: %s\n", (label == NULL ? "NULL" : label),
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node, topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (result);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd/*
908f1e1388f616898b4e515d343c0414f2a6472esd * Calculate the system information for a node. Inherit the data if
908f1e1388f616898b4e515d343c0414f2a6472esd * possible, but always create an appropriate property group.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esdint
908f1e1388f616898b4e515d343c0414f2a6472esdpi_set_system(topo_mod_t *mod, tnode_t *t_node)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd int err;
908f1e1388f616898b4e515d343c0414f2a6472esd struct utsname uts;
908f1e1388f616898b4e515d343c0414f2a6472esd char isa[MAXNAMELEN];
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (mod == NULL || t_node == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_pgroup_create(t_node, &sys_pgroup, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We failed to create the property group and it was not
908f1e1388f616898b4e515d343c0414f2a6472esd * already defined. Set the err code and return failure.
908f1e1388f616898b4e515d343c0414f2a6472esd */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd return (-1);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_inherit(t_node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA,
908f1e1388f616898b4e515d343c0414f2a6472esd &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd isa[0] = '\0';
908f1e1388f616898b4e515d343c0414f2a6472esd result = sysinfo(SI_ARCHITECTURE, isa, sizeof (isa));
908f1e1388f616898b4e515d343c0414f2a6472esd if (result == -1) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_system: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "read SI_ARCHITECTURE: %d\n", errno);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd if (strnlen(isa, MAXNAMELEN) > 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_set_string(t_node,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PROP_IMMUTABLE, isa, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "set property %s (%d) : %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PROP_ISA, err, topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_inherit(t_node, TOPO_PGROUP_SYSTEM,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PROP_MACHINE, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0 && err != ETOPO_PROP_DEFD) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = uname(&uts);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result == -1) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, errno);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_system: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "read uname: %d\n", errno);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd if (strnlen(uts.machine, sizeof (uts.machine)) > 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd result = topo_prop_set_string(t_node,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE,
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PROP_IMMUTABLE, uts.machine, &err);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /* Preserve the error and continue */
186d582bd9dbcd38e0aeea49036d47d3426a3536Surya Prakki (void) topo_mod_seterrno(mod, err);
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "pi_set_auth: failed to "
908f1e1388f616898b4e515d343c0414f2a6472esd "set property %s (%d) : %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd TOPO_PROP_MACHINE, err, topo_strerror(err));
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (0);
908f1e1388f616898b4e515d343c0414f2a6472esd}
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esdtnode_t *
908f1e1388f616898b4e515d343c0414f2a6472esdpi_node_bind(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node,
908f1e1388f616898b4e515d343c0414f2a6472esd tnode_t *t_parent, const char *hc_name, topo_instance_t inst,
908f1e1388f616898b4e515d343c0414f2a6472esd nvlist_t *fmri)
908f1e1388f616898b4e515d343c0414f2a6472esd{
908f1e1388f616898b4e515d343c0414f2a6472esd int result;
908f1e1388f616898b4e515d343c0414f2a6472esd tnode_t *t_node;
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd if (t_parent == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod,
908f1e1388f616898b4e515d343c0414f2a6472esd "cannot bind for node_0x%llx instance %d type %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node, inst, hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /* Bind this node to the parent */
908f1e1388f616898b4e515d343c0414f2a6472esd t_node = topo_node_bind(mod, t_parent, hc_name, inst, fmri);
908f1e1388f616898b4e515d343c0414f2a6472esd if (t_node == NULL) {
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod,
908f1e1388f616898b4e515d343c0414f2a6472esd "failed to bind node_0x%llx instance %d: %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node, (uint32_t)inst,
908f1e1388f616898b4e515d343c0414f2a6472esd topo_strerror(topo_mod_errno(mod)));
908f1e1388f616898b4e515d343c0414f2a6472esd return (NULL);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "bound node_0x%llx instance %d type %s\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node, inst, hc_name);
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * We have bound the node. Now decorate it with an appropriate
908f1e1388f616898b4e515d343c0414f2a6472esd * FRU and label (which may be inherited from the parent).
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier *
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * The disk enumerator requires that 'bay' nodes not set their
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * fru property.
908f1e1388f616898b4e515d343c0414f2a6472esd */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (strncmp(hc_name, BAY, strlen(BAY)) != 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier result = pi_set_frufmri(mod, mdp, mde_node, hc_name, inst,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier t_parent, t_node);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier if (result != 0) {
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier /*
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * Though we have failed to set the FRU FMRI we still
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * continue. The module errno is set by the called
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier * routine, so we report the problem and move on.
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier */
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier topo_mod_dprintf(mod,
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier "failed to set FRU FMRI for node_0x%llx\n",
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier (uint64_t)mde_node);
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier }
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = pi_set_label(mod, mdp, mde_node, t_node);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Though we have failed to set the label, we still continue.
908f1e1388f616898b4e515d343c0414f2a6472esd * The module errno is set by the called routine, so we report
908f1e1388f616898b4e515d343c0414f2a6472esd * the problem and move on.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "failed to set label for node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = pi_set_auth(mod, mdp, mde_node, t_parent, t_node);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Though we have failed to set the authority, we still
908f1e1388f616898b4e515d343c0414f2a6472esd * continue. The module errno is set by the called routine, so
908f1e1388f616898b4e515d343c0414f2a6472esd * we report the problem and move on.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "failed to set authority for "
908f1e1388f616898b4e515d343c0414f2a6472esd "node_0x%llx\n", (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd result = pi_set_system(mod, t_node);
908f1e1388f616898b4e515d343c0414f2a6472esd if (result != 0) {
908f1e1388f616898b4e515d343c0414f2a6472esd /*
908f1e1388f616898b4e515d343c0414f2a6472esd * Though we have failed to set the system group, we still
908f1e1388f616898b4e515d343c0414f2a6472esd * continue. The module errno is set by the called routine, so
908f1e1388f616898b4e515d343c0414f2a6472esd * we report the problem and move on.
908f1e1388f616898b4e515d343c0414f2a6472esd */
908f1e1388f616898b4e515d343c0414f2a6472esd topo_mod_dprintf(mod, "failed to set system for node_0x%llx\n",
908f1e1388f616898b4e515d343c0414f2a6472esd (uint64_t)mde_node);
908f1e1388f616898b4e515d343c0414f2a6472esd }
908f1e1388f616898b4e515d343c0414f2a6472esd
908f1e1388f616898b4e515d343c0414f2a6472esd return (t_node);
908f1e1388f616898b4e515d343c0414f2a6472esd}