2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <alloca.h>
2N/A#include <dirent.h>
2N/A#include <devid.h>
2N/A#include <fm/libdiskstatus.h>
2N/A#include <inttypes.h>
2N/A#include <pthread.h>
2N/A#include <strings.h>
2N/A#include <string.h>
2N/A#include <unistd.h>
2N/A#include <sys/dkio.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <sys/libdevid.h>
2N/A#include <sys/scsi/scsi_types.h>
2N/A#include <sys/byteorder.h>
2N/A#include <pthread.h>
2N/A#include <signal.h>
2N/A#include <fcntl.h>
2N/A#include <sys/ctfs.h>
2N/A#include <libcontract.h>
2N/A#include <poll.h>
2N/A#include <sys/contract/device.h>
2N/A#include <libsysevent.h>
2N/A#include <sys/sysevent/eventdefs.h>
2N/A#include <scsi/plugins/ses/vendor/sun.h>
2N/A#include <sys/devfm.h>
2N/A#include <fm/fmd_fmri.h>
2N/A
2N/A#include "disk.h"
2N/A#include "ses.h"
2N/A
2N/A#define SES_VERSION 1
2N/A
2N/A#define SES_STARTING_SUBCHASSIS 256 /* valid subchassis IDs are uint8_t */
2N/A#define NO_SUBCHASSIS ((uint64_t)-1)
2N/A
2N/Astatic int ses_snap_freq = 250; /* in milliseconds */
2N/Astatic int ses_sof_recheck = 60000; /* in miliseconds */
2N/A
2N/A#define SES_STATUS_UNAVAIL(ext, s) ((ext) ? ((s) >= SES_ESC_NOT_INSTALLED) : \
2N/A (((s) == SES_ESC_UNSUPPORTED) || ((s) >= SES_ESC_NOT_INSTALLED)))
2N/A
2N/A#define HR_SECOND 1000000000
2N/A
2N/A/*
2N/A * Because multiple SES targets can be part of a single chassis, we construct
2N/A * our own hierarchy that takes this into account. These SES targets may refer
2N/A * to the same devices (multiple paths) or to different devices (managing
2N/A * different portions of the space). We arrange things into a
2N/A * ses_enum_enclosure_t, which contains a set of ses targets, and a list of all
2N/A * nodes found so far.
2N/A */
2N/Atypedef struct ses_alt_node {
2N/A topo_list_t san_link;
2N/A ses_node_t *san_node;
2N/A ses_enum_target_t *san_target;
2N/A} ses_alt_node_t;
2N/A
2N/Atypedef struct ses_enum_node {
2N/A topo_list_t sen_link;
2N/A ses_node_t *sen_node;
2N/A topo_list_t sen_alt_nodes;
2N/A uint64_t sen_type;
2N/A uint64_t sen_instance;
2N/A ses_enum_target_t *sen_target;
2N/A} ses_enum_node_t;
2N/A
2N/Atypedef struct ses_enum_chassis {
2N/A topo_list_t sec_link;
2N/A topo_list_t sec_subchassis;
2N/A topo_list_t sec_nodes;
2N/A topo_list_t sec_targets;
2N/A const char *sec_csn;
2N/A ses_node_t *sec_enclosure;
2N/A ses_enum_target_t *sec_target;
2N/A topo_instance_t sec_instance;
2N/A topo_instance_t sec_scinstance;
2N/A topo_instance_t sec_maxinstance;
2N/A boolean_t sec_hasdev;
2N/A boolean_t sec_internal;
2N/A boolean_t sec_is_fru;
2N/A boolean_t sec_is_ext_managed;
2N/A boolean_t sec_self_report;
2N/A} ses_enum_chassis_t;
2N/A
2N/Atypedef struct ses_enum_data {
2N/A topo_list_t sed_devs;
2N/A topo_list_t sed_chassis;
2N/A ses_enum_chassis_t *sed_current;
2N/A ses_enum_target_t *sed_target;
2N/A int sed_errno;
2N/A char *sed_name;
2N/A topo_mod_t *sed_mod;
2N/A topo_instance_t sed_instance;
2N/A} ses_enum_data_t;
2N/A
2N/Atypedef struct sas_connector_phy_data {
2N/A uint64_t scpd_index;
2N/A uint64_t scpd_pm;
2N/A} sas_connector_phy_data_t;
2N/A
2N/Atypedef struct sas_connector_type {
2N/A uint64_t sct_type;
2N/A char *sct_name;
2N/A} sas_connector_type_t;
2N/A
2N/Astatic const sas_connector_type_t sas_connector_type_list[] = {
2N/A { 0x0, "Information unknown" },
2N/A { 0x1, "External SAS 4x receptacle (see SAS-2 and SFF-8470)" },
2N/A { 0x2, "External Mini SAS 4x receptacle (see SAS-2 and SFF-8088)" },
2N/A { 0xF, "Vendor-specific external connector" },
2N/A { 0x10, "Internal wide SAS 4i plug (see SAS-2 and SFF-8484)" },
2N/A { 0x11,
2N/A "Internal wide Mini SAS 4i receptacle (see SAS-2 and SFF-8087)" },
2N/A { 0x20, "Internal SAS Drive receptacle (see SAS-2 and SFF-8482)" },
2N/A { 0x21, "Internal SATA host plug (see SAS-2 and SATA-2)" },
2N/A { 0x22, "Internal SAS Drive plug (see SAS-2 and SFF-8482)" },
2N/A { 0x23, "Internal SATA device plug (see SAS-2 and SATA-2)" },
2N/A { 0x2F, "Internal SAS virtual connector" },
2N/A { 0x3F, "Vendor-specific internal connector" },
2N/A { 0x70, "Other Vendor-specific connector" },
2N/A { 0x71, "Other Vendor-specific connector" },
2N/A { 0x72, "Other Vendor-specific connector" },
2N/A { 0x73, "Other Vendor-specific connector" },
2N/A { 0x74, "Other Vendor-specific connector" },
2N/A { 0x75, "Other Vendor-specific connector" },
2N/A { 0x76, "Other Vendor-specific connector" },
2N/A { 0x77, "Other Vendor-specific connector" },
2N/A { 0x78, "Other Vendor-specific connector" },
2N/A { 0x79, "Other Vendor-specific connector" },
2N/A { 0x7A, "Other Vendor-specific connector" },
2N/A { 0x7B, "Other Vendor-specific connector" },
2N/A { 0x7C, "Other Vendor-specific connector" },
2N/A { 0x7D, "Other Vendor-specific connector" },
2N/A { 0x7E, "Other Vendor-specific connector" },
2N/A { 0x7F, "Other Vendor-specific connector" },
2N/A { 0x80, "Not Defined" }
2N/A};
2N/A
2N/A#define SAS_CONNECTOR_TYPE_CODE_NOT_DEFINED 0x80
2N/A#define SAS_CONNECTOR_TYPE_NOT_DEFINED \
2N/A "Connector type not definedi by SES-2 standard"
2N/A#define SAS_CONNECTOR_TYPE_RESERVED \
2N/A "Connector type reserved by SES-2 standard"
2N/A
2N/Atypedef struct phys_enum_type {
2N/A uint64_t pet_type;
2N/A char *pet_nodename;
2N/A char *pet_defaultlabel;
2N/A boolean_t pet_dorange;
2N/A} phys_enum_type_t;
2N/A
2N/Astatic const phys_enum_type_t phys_enum_type_list[] = {
2N/A { SES_ET_ARRAY_DEVICE, BAY, "BAY", B_TRUE },
2N/A { SES_ET_COOLING, FAN, "FAN", B_TRUE },
2N/A { SES_ET_DEVICE, BAY, "BAY", B_TRUE },
2N/A { SES_ET_ESC_ELECTRONICS, CONTROLLER, "CONTROLLER", B_TRUE },
2N/A { SES_ET_POWER_SUPPLY, PSU, "PSU", B_TRUE },
2N/A { SES_ET_SUNW_FANBOARD, FANBOARD, "FANBOARD", B_TRUE },
2N/A { SES_ET_SUNW_FANMODULE, FANMODULE, "FANMODULE", B_TRUE },
2N/A { SES_ET_SUNW_POWERBOARD, POWERBOARD, "POWERBOARD", B_TRUE },
2N/A { SES_ET_SUNW_POWERMODULE, POWERMODULE, "POWERMODULE", B_TRUE }
2N/A};
2N/A
2N/A#define N_PHYS_ENUM_TYPES (sizeof (phys_enum_type_list) / \
2N/A sizeof (phys_enum_type_list[0]))
2N/A
2N/A/*
2N/A * Structure for the hierarchical tree for element nodes.
2N/A */
2N/Atypedef struct ses_phys_tree {
2N/A ses_node_t *spt_snode;
2N/A ses_enum_node_t *spt_senumnode;
2N/A boolean_t spt_isfru;
2N/A uint64_t spt_eonlyindex;
2N/A uint64_t spt_cindex;
2N/A uint64_t spt_pindex;
2N/A uint64_t spt_maxinst;
2N/A struct ses_phys_tree *spt_parent;
2N/A struct ses_phys_tree *spt_child;
2N/A struct ses_phys_tree *spt_sibling;
2N/A tnode_t *spt_tnode;
2N/A} ses_phys_tree_t;
2N/A
2N/Atypedef enum {
2N/A SES_NEW_CHASSIS = 0x1,
2N/A SES_NEW_SUBCHASSIS = 0x2,
2N/A SES_DUP_CHASSIS = 0x4,
2N/A SES_DUP_SUBCHASSIS = 0x8
2N/A} ses_chassis_type_e;
2N/A
2N/A
2N/Astatic const topo_pgroup_info_t storage_pgroup = {
2N/A TOPO_PGROUP_STORAGE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A 1
2N/A};
2N/A
2N/Astatic const topo_pgroup_info_t smp_pgroup = {
2N/A TOPO_PGROUP_SMP,
2N/A TOPO_STABILITY_PRIVATE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A 1
2N/A};
2N/A
2N/Astatic const topo_pgroup_info_t ses_pgroup = {
2N/A TOPO_PGROUP_SES,
2N/A TOPO_STABILITY_PRIVATE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A 1
2N/A};
2N/A
2N/Astatic const topo_pgroup_info_t facmgmt_pgroup = {
2N/A TOPO_PGROUP_FACILITY_MGMT,
2N/A TOPO_STABILITY_PRIVATE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A 1
2N/A};
2N/A
2N/Astatic const topo_pgroup_info_t binding_pgroup = {
2N/A TOPO_PGROUP_BINDING,
2N/A TOPO_STABILITY_PRIVATE,
2N/A TOPO_STABILITY_PRIVATE,
2N/A 1
2N/A};
2N/A
2N/Astatic int ses_presence_state(topo_mod_t *, tnode_t *, topo_version_t,
2N/A nvlist_t *, nvlist_t **);
2N/A
2N/Astatic const topo_method_t ses_component_methods[] = {
2N/A { TOPO_METH_PRESENCE_STATE, TOPO_METH_PRESENCE_STATE_DESC,
2N/A TOPO_METH_PRESENCE_STATE_VERSION0, TOPO_STABILITY_INTERNAL,
2N/A ses_presence_state },
2N/A { TOPO_METH_FAC_ENUM, TOPO_METH_FAC_ENUM_DESC, 0,
2N/A TOPO_STABILITY_INTERNAL, ses_node_enum_facility },
2N/A { TOPO_METH_SENSOR_FAILURE, TOPO_METH_SENSOR_FAILURE_DESC,
2N/A TOPO_METH_SENSOR_FAILURE_VERSION, TOPO_STABILITY_INTERNAL,
2N/A topo_method_sensor_failure },
2N/A { NULL }
2N/A};
2N/A
2N/Astatic const topo_method_t ses_bay_methods[] = {
2N/A { TOPO_METH_FAC_ENUM, TOPO_METH_FAC_ENUM_DESC, 0,
2N/A TOPO_STABILITY_INTERNAL, ses_node_enum_facility },
2N/A { NULL }
2N/A};
2N/A
2N/Astatic const topo_method_t ses_enclosure_methods[] = {
2N/A { TOPO_METH_FAC_ENUM, TOPO_METH_FAC_ENUM_DESC, 0,
2N/A TOPO_STABILITY_INTERNAL, ses_enc_enum_facility },
2N/A { NULL }
2N/A};
2N/A
2N/A/*
2N/A * Functions for tracking ses devices which we were unable to open. We retry
2N/A * these at regular intervals using ses_sof_recheck_dir() and if we find that we
2N/A * can now open any of them then we send a sysevent to indicate that a new topo
2N/A * snapshot should be taken.
2N/A */
2N/Atypedef struct ses_open_fail_list {
2N/A struct ses_open_fail_list *sof_next;
2N/A char *sof_path;
2N/A} ses_open_fail_list_t;
2N/A
2N/Astatic ses_open_fail_list_t *ses_sofh;
2N/Astatic pthread_mutex_t ses_sofmt;
2N/A
2N/Astatic void ses_ct_print(char *ptr);
2N/Astatic void ses_sof_freeall(int needlock);
2N/Astatic int ses_check_facility_mgmt(topo_mod_t *mod,
2N/A ses_enum_chassis_t *cp, tnode_t *node, nvlist_t *props);
2N/A
2N/Astatic void
2N/Ases_sof_recheck_dir()
2N/A{
2N/A ses_target_t *target;
2N/A sysevent_id_t eid;
2N/A char buf[80];
2N/A ses_open_fail_list_t *sof;
2N/A
2N/A /*
2N/A * check list of "unable to open" devices
2N/A */
2N/A (void) pthread_mutex_lock(&ses_sofmt);
2N/A for (sof = ses_sofh; sof != NULL; sof = sof->sof_next) {
2N/A /*
2N/A * see if we can open it now
2N/A */
2N/A if ((target = ses_open(LIBSES_VERSION,
2N/A sof->sof_path)) == NULL) {
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "recheck_dir - still can't open %s", sof->sof_path);
2N/A ses_ct_print(buf);
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * ok - need to force a new snapshot via sysevent.
2N/A */
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "recheck_dir - can now open %s", sof->sof_path);
2N/A ses_ct_print(buf);
2N/A
2N/A /*
2N/A * Delete all sof entries. The sysevent will cause a new
2N/A * ses_enum(), which will create a new, updated, list.
2N/A */
2N/A ses_sof_freeall(0);
2N/A
2N/A (void) sysevent_post_event(EC_PLATFORM, ESC_PLATFORM_SP_RESET,
2N/A SUNW_VENDOR, "fmd", NULL, &eid);
2N/A ses_close(target);
2N/A break;
2N/A }
2N/A (void) pthread_mutex_unlock(&ses_sofmt);
2N/A}
2N/A
2N/A/*
2N/A * Sof allocation/free are unrelated to active topo module boundaries, so we
2N/A * use malloc/free instead of topo_mod_* functions.
2N/A */
2N/Astatic void
2N/Ases_sof_alloc(char *path)
2N/A{
2N/A ses_open_fail_list_t *sof;
2N/A
2N/A (void) pthread_mutex_lock(&ses_sofmt);
2N/A sof = calloc(1, sizeof (*sof));
2N/A sof->sof_path = strdup(path);
2N/A sof->sof_next = ses_sofh;
2N/A ses_sofh = sof;
2N/A (void) pthread_mutex_unlock(&ses_sofmt);
2N/A}
2N/A
2N/Astatic void
2N/Ases_sof_freeall(int needlock)
2N/A{
2N/A ses_open_fail_list_t *sof, *next_sof;
2N/A
2N/A if (needlock)
2N/A (void) pthread_mutex_lock(&ses_sofmt);
2N/A for (sof = ses_sofh; sof != NULL; sof = next_sof) {
2N/A next_sof = sof->sof_next;
2N/A free(sof->sof_path);
2N/A free(sof);
2N/A }
2N/A ses_sofh = NULL;
2N/A if (needlock)
2N/A (void) pthread_mutex_unlock(&ses_sofmt);
2N/A}
2N/A
2N/A/*
2N/A * functions for verifying that the ses_enum_target_t held in a device
2N/A * contract's cookie field is still valid (it may have been freed by
2N/A * ses_release()).
2N/A */
2N/Atypedef struct ses_stp_list {
2N/A struct ses_stp_list *ssl_next;
2N/A ses_enum_target_t *ssl_tgt;
2N/A} ses_stp_list_t;
2N/A
2N/Astatic ses_stp_list_t *ses_sslh;
2N/Astatic pthread_mutex_t ses_sslmt;
2N/A
2N/Astatic void
2N/Ases_ssl_alloc(topo_mod_t *mod, ses_enum_target_t *stp)
2N/A{
2N/A ses_stp_list_t *ssl;
2N/A
2N/A (void) pthread_mutex_lock(&ses_sslmt);
2N/A ssl = topo_mod_zalloc(mod, sizeof (*ssl));
2N/A topo_mod_dprintf(mod, "ssl_alloc %p", stp);
2N/A ssl->ssl_tgt = stp;
2N/A ssl->ssl_next = ses_sslh;
2N/A ses_sslh = ssl;
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A}
2N/A
2N/Astatic void
2N/Ases_ssl_free(topo_mod_t *mod, ses_enum_target_t *stp)
2N/A{
2N/A ses_stp_list_t *ssl, *prev_ssl;
2N/A
2N/A (void) pthread_mutex_lock(&ses_sslmt);
2N/A prev_ssl = NULL;
2N/A for (ssl = ses_sslh; ssl != NULL; ssl = ssl->ssl_next) {
2N/A if (ssl->ssl_tgt == stp) {
2N/A topo_mod_dprintf(mod, "ssl_free %p", ssl->ssl_tgt);
2N/A if (prev_ssl == NULL)
2N/A ses_sslh = ssl->ssl_next;
2N/A else
2N/A prev_ssl->ssl_next = ssl->ssl_next;
2N/A topo_mod_free(mod, ssl, sizeof (*ssl));
2N/A break;
2N/A }
2N/A prev_ssl = ssl;
2N/A }
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A}
2N/A
2N/Astatic int
2N/Ases_ssl_valid(ses_enum_target_t *stp)
2N/A{
2N/A ses_stp_list_t *ssl;
2N/A
2N/A for (ssl = ses_sslh; ssl != NULL; ssl = ssl->ssl_next)
2N/A if (ssl->ssl_tgt == stp)
2N/A return (1);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Functions for creating and destroying a background thread
2N/A * (ses_contract_thread) used for detecting when ses devices have been
2N/A * retired/unretired.
2N/A */
2N/Astatic struct ses_thread_s {
2N/A pthread_mutex_t mt;
2N/A pthread_t tid;
2N/A int thr_sig;
2N/A int doexit;
2N/A int count;
2N/A} sesthread = {
2N/A PTHREAD_MUTEX_INITIALIZER,
2N/A 0,
2N/A SIGTERM,
2N/A 0,
2N/A 0
2N/A};
2N/A
2N/Atypedef struct ses_mod_list {
2N/A struct ses_mod_list *smod_next;
2N/A topo_mod_t *smod_mod;
2N/A} ses_mod_list_t;
2N/A
2N/Astatic ses_mod_list_t *ses_smod;
2N/A
2N/Astatic void
2N/Ases_ct_print(char *ptr)
2N/A{
2N/A (void) pthread_mutex_lock(&sesthread.mt);
2N/A if (ses_smod != NULL && ses_smod->smod_mod != NULL)
2N/A topo_mod_dprintf(ses_smod->smod_mod, ptr);
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic void *
2N/Ases_contract_thread(void *arg)
2N/A{
2N/A int efd, ctlfd, statfd;
2N/A ct_evthdl_t ev;
2N/A ctevid_t evid;
2N/A uint_t event;
2N/A char path[PATH_MAX];
2N/A char buf[80];
2N/A ses_enum_target_t *stp;
2N/A ct_stathdl_t stathdl;
2N/A ctid_t ctid;
2N/A struct pollfd fds;
2N/A int pollret;
2N/A
2N/A ses_ct_print("start contract event thread");
2N/A efd = open64(CTFS_ROOT "/device/pbundle", O_RDONLY);
2N/A fds.fd = efd;
2N/A fds.events = POLLIN;
2N/A fds.revents = 0;
2N/A for (;;) {
2N/A /* check if we've been asked to exit */
2N/A (void) pthread_mutex_lock(&sesthread.mt);
2N/A if (sesthread.doexit) {
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A break;
2N/A }
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A
2N/A /* poll until an event arrives */
2N/A if ((pollret = poll(&fds, 1, ses_sof_recheck)) <= 0) {
2N/A if (pollret == 0) {
2N/A /*
2N/A * Timeout, check to see if an ses device can
2N/A * now be opened. The fmd DR code should have
2N/A * already gotten a sysevent associated with
2N/A * hotplug, so this 'recheck' code should not
2N/A * be necessary, but we recheck anyway - incase
2N/A * ses_open failed for some transient reason.
2N/A */
2N/A ses_sof_recheck_dir();
2N/A }
2N/A continue;
2N/A }
2N/A
2N/A /* read the event */
2N/A (void) pthread_mutex_lock(&ses_sslmt);
2N/A ses_ct_print("read contract event");
2N/A if (ct_event_read(efd, &ev) != 0) {
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A continue;
2N/A }
2N/A
2N/A /* see if it is an event we are expecting */
2N/A ctid = ct_event_get_ctid(ev);
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "got contract event ctid=%d", ctid);
2N/A ses_ct_print(buf);
2N/A event = ct_event_get_type(ev);
2N/A if (event != CT_DEV_EV_OFFLINE && event != CT_EV_NEGEND) {
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "bad contract event %x", event);
2N/A ses_ct_print(buf);
2N/A ct_event_free(ev);
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A continue;
2N/A }
2N/A
2N/A /* find target pointer saved in cookie */
2N/A evid = ct_event_get_evid(ev);
2N/A (void) snprintf(path, PATH_MAX, CTFS_ROOT "/device/%ld/status",
2N/A ctid);
2N/A statfd = open64(path, O_RDONLY);
2N/A (void) ct_status_read(statfd, CTD_COMMON, &stathdl);
2N/A stp = (ses_enum_target_t *)(uintptr_t)
2N/A ct_status_get_cookie(stathdl);
2N/A ct_status_free(stathdl);
2N/A (void) close(statfd);
2N/A
2N/A /* check if target pointer is still valid */
2N/A if (ses_ssl_valid(stp) == 0) {
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "contract already abandoned %x", event);
2N/A ses_ct_print(buf);
2N/A (void) snprintf(path, PATH_MAX,
2N/A CTFS_ROOT "/device/%ld/ctl", ctid);
2N/A ctlfd = open64(path, O_WRONLY);
2N/A if (event != CT_EV_NEGEND)
2N/A (void) ct_ctl_ack(ctlfd, evid);
2N/A else
2N/A (void) ct_ctl_abandon(ctlfd);
2N/A (void) close(ctlfd);
2N/A ct_event_free(ev);
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A continue;
2N/A }
2N/A
2N/A /* find control device for ack/abandon */
2N/A (void) pthread_mutex_lock(&stp->set_lock);
2N/A (void) snprintf(path, PATH_MAX, CTFS_ROOT "/device/%ld/ctl",
2N/A ctid);
2N/A ctlfd = open64(path, O_WRONLY);
2N/A if (event != CT_EV_NEGEND) {
2N/A /* if this is an offline event, do the offline */
2N/A ses_ct_print("got contract offline event");
2N/A if (stp->set_target) {
2N/A ses_ct_print("contract thread rele");
2N/A ses_snap_rele(stp->set_snap);
2N/A ses_close(stp->set_target);
2N/A stp->set_target = NULL;
2N/A }
2N/A (void) ct_ctl_ack(ctlfd, evid);
2N/A } else {
2N/A /* if this is the negend, then abandon the contract */
2N/A ses_ct_print("got contract negend");
2N/A if (stp->set_ctid) {
2N/A (void) snprintf(buf, sizeof (buf),
2N/A "abandon old contract %d", stp->set_ctid);
2N/A ses_ct_print(buf);
2N/A stp->set_ctid = NULL;
2N/A }
2N/A (void) ct_ctl_abandon(ctlfd);
2N/A }
2N/A (void) close(ctlfd);
2N/A (void) pthread_mutex_unlock(&stp->set_lock);
2N/A ct_event_free(ev);
2N/A (void) pthread_mutex_unlock(&ses_sslmt);
2N/A }
2N/A (void) close(efd);
2N/A return (NULL);
2N/A}
2N/A
2N/Aint
2N/Afind_thr_sig(void)
2N/A{
2N/A int i;
2N/A sigset_t oset, rset;
2N/A int sig[] = {SIGTERM, SIGUSR1, SIGUSR2};
2N/A int sig_sz = sizeof (sig) / sizeof (int);
2N/A int rc = SIGTERM;
2N/A
2N/A /* prefered set of signals that are likely used to terminate threads */
2N/A (void) sigemptyset(&oset);
2N/A (void) pthread_sigmask(SIG_SETMASK, NULL, &oset);
2N/A for (i = 0; i < sig_sz; i++) {
2N/A if (sigismember(&oset, sig[i]) == 0) {
2N/A return (sig[i]);
2N/A }
2N/A }
2N/A
2N/A /* reserved set of signals that are not allowed to terminate thread */
2N/A (void) sigemptyset(&rset);
2N/A (void) sigaddset(&rset, SIGABRT);
2N/A (void) sigaddset(&rset, SIGKILL);
2N/A (void) sigaddset(&rset, SIGSTOP);
2N/A (void) sigaddset(&rset, SIGCANCEL);
2N/A
2N/A /* Find signal that is not masked and not in the reserved list. */
2N/A for (i = 1; i < MAXSIG; i++) {
2N/A if (sigismember(&rset, i) == 1) {
2N/A continue;
2N/A }
2N/A if (sigismember(&oset, i) == 0) {
2N/A return (i);
2N/A }
2N/A }
2N/A
2N/A return (rc);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic void
2N/Ases_handler(int sig)
2N/A{
2N/A}
2N/A
2N/Astatic void
2N/Ases_thread_init(topo_mod_t *mod)
2N/A{
2N/A pthread_attr_t *attr = NULL;
2N/A struct sigaction act;
2N/A ses_mod_list_t *smod;
2N/A
2N/A (void) pthread_mutex_lock(&sesthread.mt);
2N/A sesthread.count++;
2N/A smod = topo_mod_zalloc(mod, sizeof (*smod));
2N/A smod->smod_mod = mod;
2N/A smod->smod_next = ses_smod;
2N/A ses_smod = smod;
2N/A if (sesthread.tid == 0) {
2N/A /* find a suitable signal to use for killing the thread below */
2N/A sesthread.thr_sig = find_thr_sig();
2N/A
2N/A /* if don't have a handler for this signal, create one */
2N/A (void) sigaction(sesthread.thr_sig, NULL, &act);
2N/A if (act.sa_handler == SIG_DFL || act.sa_handler == SIG_IGN)
2N/A act.sa_handler = ses_handler;
2N/A (void) sigaction(sesthread.thr_sig, &act, NULL);
2N/A
2N/A /* create a thread to listen for offline events */
2N/A (void) pthread_create(&sesthread.tid,
2N/A attr, ses_contract_thread, NULL);
2N/A }
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A}
2N/A
2N/Astatic void
2N/Ases_thread_fini(topo_mod_t *mod)
2N/A{
2N/A ses_mod_list_t *smod, *prev_smod;
2N/A
2N/A (void) pthread_mutex_lock(&sesthread.mt);
2N/A prev_smod = NULL;
2N/A for (smod = ses_smod; smod != NULL; smod = smod->smod_next) {
2N/A if (smod->smod_mod == mod) {
2N/A if (prev_smod == NULL)
2N/A ses_smod = smod->smod_next;
2N/A else
2N/A prev_smod->smod_next = smod->smod_next;
2N/A topo_mod_free(mod, smod, sizeof (*smod));
2N/A break;
2N/A }
2N/A prev_smod = smod;
2N/A }
2N/A if (--sesthread.count > 0) {
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A return;
2N/A }
2N/A sesthread.doexit = 1;
2N/A (void) pthread_mutex_unlock(&sesthread.mt);
2N/A (void) pthread_kill(sesthread.tid, sesthread.thr_sig);
2N/A (void) pthread_join(sesthread.tid, NULL);
2N/A sesthread.tid = 0;
2N/A}
2N/A
2N/Astatic void
2N/Ases_create_contract(topo_mod_t *mod, ses_enum_target_t *stp)
2N/A{
2N/A int tfd, len, rval;
2N/A char link_path[PATH_MAX], *ptr;
2N/A
2N/A stp->set_ctid = NULL;
2N/A
2N/A /* convert "/dev" path into "/devices" path */
2N/A if ((len = readlink(stp->set_devpath, link_path, PATH_MAX)) < 0) {
2N/A topo_mod_dprintf(mod, "readlink failed");
2N/A return;
2N/A }
2N/A link_path[len] = '\0';
2N/A
2N/A /* set up template to create new contract */
2N/A tfd = open64(CTFS_ROOT "/device/template", O_RDWR);
2N/A (void) ct_tmpl_set_critical(tfd, CT_DEV_EV_OFFLINE);
2N/A (void) ct_tmpl_set_cookie(tfd, (uint64_t)(uintptr_t)stp);
2N/A
2N/A /* strip "../../devices" off the front and create the contract */
2N/A ptr = strstr(link_path, "devices");
2N/A if (ptr == NULL) {
2N/A topo_mod_dprintf(mod, "invalid device path %s", link_path);
2N/A close(tfd);
2N/A return;
2N/A }
2N/A ptr += strlen("devices");
2N/A if ((rval = ct_dev_tmpl_set_minor(tfd, ptr)) != 0)
2N/A topo_mod_dprintf(mod, "failed to set minor %s rval = %d",
2N/A ptr, rval);
2N/A else if ((rval = ct_tmpl_create(tfd, &stp->set_ctid)) != 0)
2N/A topo_mod_dprintf(mod, "failed to create ctid rval = %d", rval);
2N/A else
2N/A topo_mod_dprintf(mod, "created ctid=%d", stp->set_ctid);
2N/A (void) close(tfd);
2N/A}
2N/A
2N/Astatic void
2N/Ases_target_free(topo_mod_t *mod, ses_enum_target_t *stp)
2N/A{
2N/A if (--stp->set_refcount == 0) {
2N/A /* check if already closed due to contract offline request */
2N/A (void) pthread_mutex_lock(&stp->set_lock);
2N/A if (stp->set_target) {
2N/A ses_snap_rele(stp->set_snap);
2N/A ses_close(stp->set_target);
2N/A stp->set_target = NULL;
2N/A }
2N/A if (stp->set_ctid) {
2N/A int ctlfd;
2N/A char path[PATH_MAX];
2N/A
2N/A topo_mod_dprintf(mod, "abandon old contract %d",
2N/A stp->set_ctid);
2N/A (void) snprintf(path, PATH_MAX,
2N/A CTFS_ROOT "/device/%ld/ctl", stp->set_ctid);
2N/A ctlfd = open64(path, O_WRONLY);
2N/A (void) ct_ctl_abandon(ctlfd);
2N/A (void) close(ctlfd);
2N/A stp->set_ctid = NULL;
2N/A }
2N/A (void) pthread_mutex_unlock(&stp->set_lock);
2N/A ses_ssl_free(mod, stp);
2N/A topo_mod_strfree(mod, stp->set_devpath);
2N/A topo_mod_free(mod, stp, sizeof (ses_enum_target_t));
2N/A }
2N/A}
2N/A
2N/Astatic void
2N/Ases_data_free(ses_enum_data_t *sdp, ses_enum_chassis_t *pcp)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A ses_enum_chassis_t *cp;
2N/A ses_enum_node_t *np;
2N/A ses_enum_target_t *tp;
2N/A ses_alt_node_t *ap;
2N/A topo_list_t *cpl;
2N/A
2N/A
2N/A if (pcp != NULL)
2N/A cpl = &pcp->sec_subchassis;
2N/A else
2N/A cpl = &sdp->sed_chassis;
2N/A
2N/A while ((cp = topo_list_next(cpl)) != NULL) {
2N/A topo_list_delete(cpl, cp);
2N/A
2N/A while ((np = topo_list_next(&cp->sec_nodes)) != NULL) {
2N/A while ((ap = topo_list_next(&np->sen_alt_nodes)) !=
2N/A NULL) {
2N/A topo_list_delete(&np->sen_alt_nodes, ap);
2N/A topo_mod_free(mod, ap, sizeof (ses_alt_node_t));
2N/A }
2N/A topo_list_delete(&cp->sec_nodes, np);
2N/A topo_mod_free(mod, np, sizeof (ses_enum_node_t));
2N/A }
2N/A
2N/A while ((tp = topo_list_next(&cp->sec_targets)) != NULL) {
2N/A topo_list_delete(&cp->sec_targets, tp);
2N/A ses_target_free(mod, tp);
2N/A }
2N/A
2N/A topo_mod_free(mod, cp, sizeof (ses_enum_chassis_t));
2N/A }
2N/A
2N/A if (pcp == NULL) {
2N/A ses_dev_list_free(mod, &sdp->sed_devs);
2N/A topo_mod_free(mod, sdp, sizeof (ses_enum_data_t));
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Return a current instance of the node. This is somewhat complicated because
2N/A * we need to take a new snapshot in order to get the new data, but we don't
2N/A * want to be constantly taking SES snapshots if the consumer is going to do a
2N/A * series of queries. So we adopt the strategy of assuming that the SES state
2N/A * is not going to be rapidly changing, and limit our snapshot frequency to
2N/A * some defined bounds.
2N/A */
2N/Ases_node_t *
2N/Ases_node_lock(topo_mod_t *mod, tnode_t *tn)
2N/A{
2N/A ses_enum_target_t *tp = topo_node_getspecific(tn);
2N/A hrtime_t now;
2N/A ses_snap_t *snap;
2N/A int err;
2N/A uint64_t nodeid;
2N/A ses_node_t *np;
2N/A
2N/A if (tp == NULL) {
2N/A (void) topo_mod_seterrno(mod, EMOD_METHOD_NOTSUP);
2N/A return (NULL);
2N/A }
2N/A
2N/A (void) pthread_mutex_lock(&tp->set_lock);
2N/A
2N/A /*
2N/A * Determine if we need to take a new snapshot.
2N/A */
2N/A now = gethrtime();
2N/A
2N/A if (tp->set_target == NULL) {
2N/A /*
2N/A * We may have closed the device but not yet abandoned the
2N/A * contract (ie we've had the offline event but not yet the
2N/A * negend). If so, just return failure.
2N/A */
2N/A if (tp->set_ctid != NULL) {
2N/A (void) topo_mod_seterrno(mod, EMOD_METHOD_NOTSUP);
2N/A (void) pthread_mutex_unlock(&tp->set_lock);
2N/A return (NULL);
2N/A }
2N/A
2N/A /*
2N/A * The device has been closed due to a contract offline
2N/A * request, then we need to reopen it and create a new contract.
2N/A */
2N/A if ((tp->set_target =
2N/A ses_open(LIBSES_VERSION, tp->set_devpath)) == NULL) {
2N/A sysevent_id_t eid;
2N/A
2N/A (void) topo_mod_seterrno(mod, EMOD_METHOD_NOTSUP);
2N/A (void) pthread_mutex_unlock(&tp->set_lock);
2N/A topo_mod_dprintf(mod, "ses_node_lock - "
2N/A "can no longer open %s", tp->set_devpath);
2N/A (void) sysevent_post_event(EC_PLATFORM,
2N/A ESC_PLATFORM_SP_RESET, SUNW_VENDOR, "fmd", NULL,
2N/A &eid);
2N/A return (NULL);
2N/A }
2N/A topo_mod_dprintf(mod, "reopen contract");
2N/A ses_create_contract(mod, tp);
2N/A tp->set_snap = ses_snap_hold(tp->set_target);
2N/A tp->set_snaptime = gethrtime();
2N/A } else if (now - tp->set_snaptime > (ses_snap_freq * 1000 * 1000) &&
2N/A (snap = ses_snap_new(tp->set_target)) != NULL) {
2N/A if (ses_snap_generation(snap) !=
2N/A ses_snap_generation(tp->set_snap)) {
2N/A /*
2N/A * If we find ourselves in this situation, we're in
2N/A * trouble. The generation count has changed, which
2N/A * indicates that our current topology is out of date.
2N/A * But we need to consult the new topology in order to
2N/A * determine presence at this moment in time. We can't
2N/A * go back and change the topo snapshot in situ, so
2N/A * we'll just have to fail the call in this unlikely
2N/A * scenario.
2N/A */
2N/A ses_snap_rele(snap);
2N/A (void) topo_mod_seterrno(mod, EMOD_METHOD_NOTSUP);
2N/A (void) pthread_mutex_unlock(&tp->set_lock);
2N/A return (NULL);
2N/A } else {
2N/A ses_snap_rele(tp->set_snap);
2N/A tp->set_snap = snap;
2N/A }
2N/A tp->set_snaptime = gethrtime();
2N/A }
2N/A
2N/A snap = tp->set_snap;
2N/A
2N/A verify(topo_prop_get_uint64(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_NODE_ID, &nodeid, &err) == 0);
2N/A verify((np = ses_node_lookup(snap, nodeid)) != NULL);
2N/A
2N/A return (np);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Avoid
2N/Ases_node_unlock(topo_mod_t *mod, tnode_t *tn)
2N/A{
2N/A ses_enum_target_t *tp = topo_node_getspecific(tn);
2N/A
2N/A verify(tp != NULL);
2N/A
2N/A (void) pthread_mutex_unlock(&tp->set_lock);
2N/A}
2N/A
2N/A/*
2N/A * Determine if the element is present.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_presence_state(topo_mod_t *mod, tnode_t *tn, topo_version_t version,
2N/A nvlist_t *in, nvlist_t **out)
2N/A{
2N/A int presence_state;
2N/A ses_node_t *np;
2N/A nvlist_t *props, *nvl;
2N/A uint64_t status;
2N/A
2N/A if ((np = ses_node_lock(mod, tn)) == NULL)
2N/A return (-1);
2N/A
2N/A verify((props = ses_node_props(np)) != NULL);
2N/A verify(nvlist_lookup_uint64(props,
2N/A SES_PROP_STATUS_CODE, &status) == 0);
2N/A
2N/A ses_node_unlock(mod, tn);
2N/A
2N/A /*
2N/A * No serial number support yet - so just check if somerthing is there.
2N/A */
2N/A presence_state = (status != SES_ESC_NOT_INSTALLED) ?
2N/A FMD_OBJ_STATE_UNKNOWN : FMD_OBJ_STATE_NOT_PRESENT;
2N/A
2N/A if (topo_mod_nvalloc(mod, &nvl, NV_UNIQUE_NAME) != 0)
2N/A return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
2N/A
2N/A if (nvlist_add_uint32(nvl, TOPO_METH_PRESENCE_STATE_RET,
2N/A presence_state) != 0) {
2N/A nvlist_free(nvl);
2N/A return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
2N/A }
2N/A
2N/A *out = nvl;
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Sets standard properties for a ses node (enclosure, bay, controller
2N/A * or expander).
2N/A * This includes setting the FRU, as well as setting the
2N/A * authority information. When the fru topo node(frutn) is not NULL
2N/A * its resouce should be used as FRU.
2N/A */
2N/Astatic int
2N/Ases_set_standard_props(topo_mod_t *mod, tnode_t *frutn, tnode_t *tn,
2N/A nvlist_t *auth, uint64_t nodeid, const char *path)
2N/A{
2N/A int err;
2N/A char *chassis_name, *chassis_sn;
2N/A nvlist_t *fmri;
2N/A
2N/A /*
2N/A * Set the authority explicitly if specified.
2N/A */
2N/A if (auth) {
2N/A verify(nvlist_lookup_string(auth, FM_FMRI_AUTH_V1_CHASSIS_NM,
2N/A &chassis_name) == 0);
2N/A verify(nvlist_lookup_string(auth, FM_FMRI_AUTH_V1_CHASSIS_SN,
2N/A &chassis_sn) == 0);
2N/A
2N/A if (topo_prop_set_string(tn, FM_FMRI_AUTHORITY,
2N/A FM_FMRI_AUTH_V1_CHASSIS_NM, TOPO_PROP_IMMUTABLE,
2N/A chassis_name, &err) != 0 ||
2N/A topo_prop_set_string(tn, FM_FMRI_AUTHORITY,
2N/A FM_FMRI_AUTH_V1_CHASSIS_SN, TOPO_PROP_IMMUTABLE,
2N/A chassis_sn, &err) != 0) {
2N/A topo_mod_dprintf(mod, "failed to add authority "
2N/A "properties: %s\n", topo_strerror(err));
2N/A return (topo_mod_seterrno(mod, err));
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Copy the resource and set that as the FRU.
2N/A */
2N/A if (frutn != NULL) {
2N/A if (topo_node_resource(frutn, &fmri, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_resource() failed : %s\n",
2N/A topo_strerror(err));
2N/A return (topo_mod_seterrno(mod, err));
2N/A }
2N/A } else {
2N/A if (topo_node_resource(tn, &fmri, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_resource() failed : %s\n",
2N/A topo_strerror(err));
2N/A return (topo_mod_seterrno(mod, err));
2N/A }
2N/A }
2N/A
2N/A if (topo_node_fru_set(tn, fmri, 0, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_fru_set() failed : %s\n",
2N/A topo_strerror(err));
2N/A nvlist_free(fmri);
2N/A return (topo_mod_seterrno(mod, err));
2N/A }
2N/A
2N/A nvlist_free(fmri);
2N/A
2N/A /*
2N/A * Set the SES-specific properties so that consumers can query
2N/A * additional information about the particular SES element.
2N/A */
2N/A if (topo_pgroup_create(tn, &ses_pgroup, &err) != 0) {
2N/A topo_mod_dprintf(mod, "failed to create propgroup "
2N/A "%s: %s\n", TOPO_PGROUP_SES, topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A
2N/A if (topo_prop_set_uint64(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_NODE_ID, TOPO_PROP_IMMUTABLE,
2N/A nodeid, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to create property %s: %s\n",
2N/A TOPO_PROP_NODE_ID, topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A
2N/A if (topo_prop_set_string(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_ENUMERATION_TARGET_PATH, TOPO_PROP_IMMUTABLE,
2N/A path, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to create property %s: %s\n",
2N/A TOPO_PROP_ENUMERATION_TARGET_PATH, topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Callback to add a disk to a given bay. We first check the status-code to
2N/A * determine if a disk is present, ignoring those that aren't in an appropriate
2N/A * state. We then scan the parent bay node's SAS address array to determine
2N/A * possible attached SAS addresses. We create a disk node if the disk is not
2N/A * SAS or the SES target does not support the necessary pages for this; if we
2N/A * find the SAS address, we create a disk node and also correlate it with
2N/A * the corresponding Solaris device node to fill in the rest of the data.
2N/A */
2N/Astatic int
2N/Ases_create_disk(ses_enum_data_t *sdp, tnode_t *pnode, nvlist_t *props)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A uint64_t status;
2N/A uint_t s, npath;
2N/A char **paths = NULL;
2N/A int err = 0, empty = 0;
2N/A tnode_t *child = NULL;
2N/A
2N/A /*
2N/A * Skip devices that are not in a present (and possibly damaged) state.
2N/A */
2N/A if (nvlist_lookup_uint64(props, SES_PROP_STATUS_CODE, &status) != 0)
2N/A return (0);
2N/A
2N/A if ((topo_pgroup_create(pnode, &binding_pgroup, &err) != 0) &&
2N/A (err != ETOPO_PROP_DEFD)) {
2N/A topo_mod_dprintf(mod, "failed to create propgroup "
2N/A "%s: %s\n", TOPO_PGROUP_BINDING, topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A
2N/A /*
2N/A * When the bay element status indicate the occupant is not there
2N/A * set the disk binding type to empty and the failback method to none.
2N/A */
2N/A if (status != SES_ESC_UNSUPPORTED &&
2N/A status != SES_ESC_OK &&
2N/A status != SES_ESC_CRITICAL &&
2N/A status != SES_ESC_NONCRITICAL &&
2N/A status != SES_ESC_UNRECOVERABLE &&
2N/A status != SES_ESC_NO_ACCESS) {
2N/A empty = 1;
2N/A }
2N/A
2N/A /*
2N/A * If SAS address which represents a target port is not found
2N/A * consider it is an empty bay.
2N/A * Note that TOPO_PROP_SAS_ADDR prop includes SAS address from
2N/A * alternate elements that represent the same device.
2N/A */
2N/A if (topo_prop_get_string_array(pnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SAS_ADDR, &paths, &npath, &err) != 0) {
2N/A empty = 1;
2N/A /* set to 0 for handling exit with an error. */
2N/A npath = 0;
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "found attached disk");
2N/A
2N/A err = 0;
2N/A
2N/A /* Set occupant presence property. */
2N/A if (topo_prop_set_string(pnode,
2N/A TOPO_PGROUP_BINDING, TOPO_BINDING_OCCUPANT_PRESENCE,
2N/A TOPO_PROP_IMMUTABLE, empty ?
2N/A OCCUPANT_NOT_DETECTED : OCCUPANT_DETECTED, &err) != 0) {
2N/A topo_mod_dprintf(mod, "failed to set occupant presence "
2N/A "property: %s\n", topo_strerror(err));
2N/A err = -1;
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * If target ports prop is avaiablle set the binding method and
2N/A * occupant target port properties. When the props not set
2N/A * it is considered to an empty bay enumeration and the disk enumerator
2N/A * should handle the case.
2N/A */
2N/A if (paths) {
2N/A if (topo_prop_set_string(pnode,
2N/A TOPO_PGROUP_BINDING, TOPO_BINDING_METHOD,
2N/A TOPO_PROP_IMMUTABLE, TARGET_PORT_BINDING, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to set binding method: %s\n",
2N/A topo_strerror(err));
2N/A err = -1;
2N/A goto error;
2N/A }
2N/A
2N/A if (topo_prop_set_string_array(pnode, TOPO_PGROUP_BINDING,
2N/A TOPO_BINDING_OCCUPANT_TARGET_PORTS, TOPO_PROP_IMMUTABLE,
2N/A (const char **)paths, npath, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to set target ports property: "
2N/A "%s\n", topo_strerror(err));
2N/A err = -1;
2N/A goto error;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Create the disk range.
2N/A */
2N/A if (topo_node_range_create(mod, pnode, DISK, 0, 0) != 0) {
2N/A topo_mod_dprintf(mod, "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A err = -1;
2N/A goto error;
2N/A }
2N/A
2N/A if (topo_mod_load(mod, DISK, TOPO_VERSION) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_mod_load failed module: %s\n",
2N/A DISK, topo_strerror(topo_mod_errno(mod)));
2N/A err = (topo_mod_errno(mod));
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * Call the disk enumerator to create a disk node under the given bay.
2N/A */
2N/A err = topo_mod_enumerate(mod, pnode, DISK, DISK, 0, 0, NULL);
2N/A
2N/A /* copy sas_addresses (target-ports) from parent (with 'w'added) */
2N/A if (err == 0) {
2N/A /* There should be a single child disk node if exists. */
2N/A for (child = topo_child_first(pnode); child != NULL;
2N/A child = topo_child_next(pnode, child)) {
2N/A if (strcmp(topo_node_name(child), DISK) == 0)
2N/A break;
2N/A }
2N/A
2N/A if (child == NULL) {
2N/A /*
2N/A * It is okay not to have a child disk node.
2N/A * For example the bay may be empty and the disk
2N/A * enumerator may or may not create a disk node.
2N/A */
2N/A topo_mod_dprintf(mod,
2N/A "failed to locate the child disk node\n");
2N/A goto error;
2N/A }
2N/A
2N/A int i;
2N/A char **tports;
2N/A uint64_t wwn;
2N/A
2N/A tports = topo_mod_zalloc(mod, sizeof (char *) * npath);
2N/A if (tports != NULL) {
2N/A for (i = 0; i < npath; i++) {
2N/A if (scsi_wwnstr_to_wwn(paths[i], &wwn) !=
2N/A DDI_SUCCESS)
2N/A break;
2N/A tports[i] = scsi_wwn_to_wwnstr(wwn, 1, NULL);
2N/A if (tports[i] == NULL)
2N/A break;
2N/A }
2N/A /* if they all worked then create the property */
2N/A if (i == npath) {
2N/A (void) topo_prop_set_string_array(child,
2N/A TOPO_PGROUP_STORAGE,
2N/A TOPO_STORAGE_TARGET_PORT_L0IDS,
2N/A TOPO_PROP_IMMUTABLE, (const char **)tports,
2N/A npath, &err);
2N/A }
2N/A
2N/A for (i = 0; i < npath; i++)
2N/A if (tports[i] != NULL)
2N/A scsi_free_wwnstr(tports[i]);
2N/A topo_mod_free(mod, tports, sizeof (char *) * npath);
2N/A }
2N/A }
2N/A
2N/Aerror:
2N/A for (s = 0; s < npath; s++)
2N/A topo_mod_free(mod, paths[s], strlen(paths[s]) + 1);
2N/A topo_mod_free(mod, paths, npath * sizeof (char *));
2N/A
2N/A return (err);
2N/A}
2N/A
2N/Astatic int
2N/Ases_add_bay_props(topo_mod_t *mod, tnode_t *tn, ses_enum_node_t *snp)
2N/A{
2N/A ses_alt_node_t *ap;
2N/A ses_node_t *np;
2N/A nvlist_t *props;
2N/A
2N/A nvlist_t **phys;
2N/A uint_t i, j, n_phys, all_phys = 0;
2N/A char **paths;
2N/A uint64_t addr;
2N/A size_t len;
2N/A int terr, err = -1;
2N/A
2N/A for (ap = topo_list_next(&snp->sen_alt_nodes); ap != NULL;
2N/A ap = topo_list_next(ap)) {
2N/A np = ap->san_node;
2N/A props = ses_node_props(np);
2N/A
2N/A if (nvlist_lookup_nvlist_array(props, SES_SAS_PROP_PHYS,
2N/A &phys, &n_phys) != 0)
2N/A continue;
2N/A
2N/A all_phys += n_phys;
2N/A }
2N/A
2N/A if (all_phys == 0)
2N/A return (0);
2N/A
2N/A if ((paths = topo_mod_zalloc(mod, all_phys * sizeof (char *))) == NULL)
2N/A return (-1);
2N/A
2N/A for (i = 0, ap = topo_list_next(&snp->sen_alt_nodes); ap != NULL;
2N/A ap = topo_list_next(ap)) {
2N/A np = ap->san_node;
2N/A props = ses_node_props(np);
2N/A
2N/A if (nvlist_lookup_nvlist_array(props, SES_SAS_PROP_PHYS,
2N/A &phys, &n_phys) != 0)
2N/A continue;
2N/A
2N/A for (j = 0; j < n_phys; j++) {
2N/A if (nvlist_lookup_uint64(phys[j], SES_SAS_PROP_ADDR,
2N/A &addr) != 0)
2N/A continue;
2N/A
2N/A len = snprintf(NULL, 0, "%016llx", addr) + 1;
2N/A if ((paths[i] = topo_mod_alloc(mod, len)) == NULL)
2N/A goto error;
2N/A
2N/A (void) snprintf(paths[i], len, "%016llx", addr);
2N/A
2N/A ++i;
2N/A }
2N/A }
2N/A
2N/A err = topo_prop_set_string_array(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SAS_ADDR, TOPO_PROP_IMMUTABLE,
2N/A (const char **)paths, i, &terr);
2N/A if (err != 0)
2N/A err = topo_mod_seterrno(mod, terr);
2N/A
2N/Aerror:
2N/A for (i = 0; i < all_phys && paths[i] != NULL; i++)
2N/A topo_mod_free(mod, paths[i], strlen(paths[i]) + 1);
2N/A topo_mod_free(mod, paths, all_phys * sizeof (char *));
2N/A
2N/A return (err);
2N/A}
2N/A
2N/A/*
2N/A * Create facility management mode for the given topo node.
2N/A */
2N/Astatic int
2N/Ases_check_facility_mgmt(topo_mod_t *mod, ses_enum_chassis_t *cp,
2N/A tnode_t *node, nvlist_t *props)
2N/A{
2N/A int err, selfmng = 0, enclrpt = 0;
2N/A boolean_t managed = B_FALSE;
2N/A uint32_t pmanaged;
2N/A
2N/A /*
2N/A * For the SAS elements inside an internal enclosure
2N/A * no facility management needs to be checked.
2N/A */
2N/A if (cp->sec_internal)
2N/A return (0);
2N/A
2N/A /*
2N/A * No sensors for the BAY node. The occupant disk has
2N/A * temperature sensor that is read by the disk transport
2N/A * through the log sense command. The BAY service LED is
2N/A * managed by the host FMA so no facility management
2N/A * properties need to be specified.
2N/A */
2N/A if (strcmp(topo_node_name(node), BAY) == 0)
2N/A return (0);
2N/A
2N/A /*
2N/A * Following areas are checked for LED facility management.
2N/A *
2N/A * 1. When there exists a FRU element that self-manages the service
2N/A * LED within such enclosure like PSU the corresponding SES element
2N/A * node should report LIBSES_PROP_SVCLED_SELF_MANAGED.
2N/A *
2N/A * 2. parent node reports TOPO_FACMGMT_SVCLED_SELF_MANAGED prop.
2N/A *
2N/A * The child node inherits the parent node setting for the
2N/A * TOPO_FACMGMT_SVCLED_SELF_MANAGED prop.
2N/A * This will avoid parsing the ancestor nodes by the reponse agent
2N/A * like the fru monitor to check the setting for the service LED
2N/A * management.
2N/A *
2N/A * 3. for an enclosure, check if it is externally managed like
2N/A * Genesis and Jurojin. If not, inidcate that the enclosure is
2N/A * self-managed by setting TOPO_FACMGMT_SVCLED_SELF_MANAGED
2N/A * proerpty. Its child nodes will inherit the property as
2N/A * appopriate.
2N/A *
2N/A * Note:
2N/A * When the TOPO_FACMGMT_SVCLED_SELF_MANAGED prop doesn't exist
2N/A * the associated service LED for the topo node is considered to be
2N/A * externally managed like the BAY/disk nodes.
2N/A */
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_PROP_SVCLED_SELF_MANAGED, &managed) == 0) {
2N/A if (managed)
2N/A selfmng = 1;
2N/A } else if (topo_prop_get_uint32(topo_node_parent(node),
2N/A TOPO_PGROUP_FACILITY_MGMT, TOPO_FACMGMT_SVCLED_SELF_MANAGED,
2N/A &pmanaged, &err) == 0) {
2N/A if (pmanaged)
2N/A selfmng = 1;
2N/A } else {
2N/A /*
2N/A * Check the enclosure for LIBSES_PROP_FAULT_EXT_MANAGED
2N/A * property. If it is not externally managed or the prop
2N/A * doesn't exist, the service LED should be self managed.
2N/A */
2N/A if ((strcmp(topo_node_name(node), SES_ENCLOSURE) == 0) ||
2N/A (strcmp(topo_node_name(node), SUBCHASSIS) == 0)) {
2N/A if (!cp->sec_is_ext_managed) {
2N/A selfmng = 1;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Following areas may need to be checked for SENSOR facility
2N/A * management.
2N/A *
2N/A * 1. the enclosure self reports out-of-range error for all
2N/A * sensors then no need to set the property for the individual
2N/A * topo node.
2N/A *
2N/A * 2. When the enclosure self-reports sensors for a subset of its
2N/A * components so the sec_self_report flag can not be set for the
2N/A * enclosure another property like
2N/A * "libses-elem-sensor-self-reported" needs to be reported
2N/A * through libses discovery to indicate that an individual
2N/A * SES element has its sensors self-reported.
2N/A *
2N/A * Currently no enclosure with behavie #2 so we just handle
2N/A * enclosure level self-reporting.
2N/A */
2N/A if (cp->sec_self_report) {
2N/A if ((strcmp(topo_node_name(node), SES_ENCLOSURE) == 0) ||
2N/A (strcmp(topo_node_name(node), SUBCHASSIS) == 0)) {
2N/A enclrpt = 1;
2N/A }
2N/A }
2N/A
2N/A /* create the facility management property group. */
2N/A if (selfmng || enclrpt) {
2N/A topo_mod_dprintf(mod, "creating %s properties: "
2N/A "%s %s %s", TOPO_PGROUP_FACILITY_MGMT, selfmng ?
2N/A TOPO_FACMGMT_SVCLED_SELF_MANAGED : "",
2N/A enclrpt ? TOPO_FACMGMT_ENCL_SENSOR_SELF_REPORTED : "");
2N/A if ((topo_pgroup_create(node, &facmgmt_pgroup, &err) != 0) &&
2N/A (err != ETOPO_PROP_DEFD)) {
2N/A topo_mod_dprintf(mod, "failed to create propgroup "
2N/A "%s: %s\n", TOPO_PGROUP_FACILITY_MGMT,
2N/A topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A } else {
2N/A return (0);
2N/A }
2N/A
2N/A /* create the service led self managed property. */
2N/A if (selfmng) {
2N/A if ((topo_prop_set_uint32(node,
2N/A TOPO_PGROUP_FACILITY_MGMT,
2N/A TOPO_FACMGMT_SVCLED_SELF_MANAGED,
2N/A TOPO_PROP_IMMUTABLE, selfmng, &err) != 0) &&
2N/A (err != ETOPO_PROP_DEFD)) {
2N/A topo_mod_dprintf(mod, "failed to set facility "
2N/A "management property %s: %s\n",
2N/A TOPO_FACMGMT_SVCLED_SELF_MANAGED,
2N/A topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A /* create the enclosure sensor self reported property. */
2N/A if (enclrpt) {
2N/A if ((topo_prop_set_uint32(node,
2N/A TOPO_PGROUP_FACILITY_MGMT,
2N/A TOPO_FACMGMT_ENCL_SENSOR_SELF_REPORTED,
2N/A TOPO_PROP_IMMUTABLE, enclrpt, &err) != 0) &&
2N/A (err != ETOPO_PROP_DEFD)) {
2N/A topo_mod_dprintf(mod, "failed to set facility "
2N/A "management property %s: %s\n",
2N/A TOPO_FACMGMT_ENCL_SENSOR_SELF_REPORTED,
2N/A topo_strerror(err));
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Callback to create a basic node (bay, psu, fan, or controller and expander).
2N/A */
2N/Astatic int
2N/Ases_create_generic(ses_enum_data_t *sdp, ses_enum_chassis_t *cp,
2N/A ses_enum_node_t *snp, tnode_t *pnode, tnode_t *frutn,
2N/A const char *nodename, const char *labelname, tnode_t **node)
2N/A{
2N/A ses_node_t *np = snp->sen_node;
2N/A ses_node_t *parent;
2N/A ses_alt_node_t *anp;
2N/A uint64_t instance = snp->sen_instance;
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A nvlist_t *props, *aprops;
2N/A nvlist_t *auth = NULL, *fmri = NULL;
2N/A tnode_t *tn = NULL;
2N/A char label[128];
2N/A int err, i = 0;
2N/A char *part = NULL, *serial = NULL, *revision = NULL;
2N/A char *desc;
2N/A boolean_t report;
2N/A uint64_t sasaddr;
2N/A char sasaddr_str[17];
2N/A ses_di_node_t *dnode;
2N/A boolean_t found = B_FALSE;
2N/A char **rt_paths = NULL;
2N/A int rt_count = 0;
2N/A
2N/A props = ses_node_props(np);
2N/A
2N/A /*
2N/A * Each SIM on a JBOD does not report the peer SIMs fruprom, and for
2N/A * this reason, we can't just trust the information from one ses traget
2N/A * for the fru information for CONTROLLER nodes. The sen_alt_nodes
2N/A * contains the list of all ses nodes that match this nodes'
2N/A * type/instance, for this enclosure. For all other components, any
2N/A * target should report the correct information.
2N/A */
2N/A if (strcmp(nodename, CONTROLLER) == 0) {
2N/A for (anp = topo_list_next(&(snp->sen_alt_nodes)); anp != NULL;
2N/A anp = topo_list_next(anp)) {
2N/A aprops = ses_node_props(anp->san_node);
2N/A
2N/A if ((part != NULL || nvlist_lookup_string(aprops,
2N/A LIBSES_PROP_PART, &part) == 0) &&
2N/A (serial != NULL || nvlist_lookup_string(aprops,
2N/A LIBSES_PROP_SERIAL, &serial) == 0))
2N/A break;
2N/A }
2N/A } else {
2N/A (void) nvlist_lookup_string(props, LIBSES_PROP_PART, &part);
2N/A (void) nvlist_lookup_string(props, LIBSES_PROP_SERIAL, &serial);
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "adding %s %llu", nodename, instance);
2N/A
2N/A /*
2N/A * Create the node. The interesting information is all copied from the
2N/A * parent enclosure node, so there is not much to do.
2N/A */
2N/A if ((auth = topo_mod_auth(mod, pnode)) == NULL)
2N/A goto error;
2N/A
2N/A /*
2N/A * We want to report revision information for the controller nodes, but
2N/A * we do not get per-element revision information. However, we do have
2N/A * revision information for the entire enclosure, and we can use the
2N/A * 'reported-via' property to know that this controller corresponds to
2N/A * the given revision information. This means we cannot get revision
2N/A * information for targets we are not explicitly connected to, but
2N/A * there is little we can do about the situation.
2N/A */
2N/A if (strcmp(nodename, CONTROLLER) == 0) {
2N/A for (anp = topo_list_next(&(snp->sen_alt_nodes));
2N/A anp != NULL && revision == NULL;
2N/A anp = topo_list_next(anp)) {
2N/A if (nvlist_lookup_boolean_value(ses_node_props(
2N/A anp->san_node), SES_PROP_REPORT, &report) != 0 ||
2N/A !report)
2N/A continue;
2N/A
2N/A for (parent = ses_node_parent(anp->san_node);
2N/A parent != NULL; parent = ses_node_parent(parent)) {
2N/A if (ses_node_type(parent) ==
2N/A SES_NODE_ENCLOSURE) {
2N/A (void) nvlist_lookup_string(
2N/A ses_node_props(parent),
2N/A SES_EN_PROP_REV, &revision);
2N/A found = B_TRUE;
2N/A break;
2N/A }
2N/A }
2N/A if (found)
2N/A break;
2N/A }
2N/A } else if (strcmp(nodename, SASEXPANDER) == 0) {
2N/A /*
2N/A * Some enclosure like Genesis can have multiple
2N/A * SAS exapnders (with SES and SMP services)
2N/A * associated with a single controller.
2N/A * The revison of each SAS expander may be different
2N/A * since a firmware is downloaded on them separately.
2N/A * Here we capture the revision info of an individual
2N/A * exapander from an smp node firmware revison property
2N/A * which is acquired through devinfo snapshot.
2N/A */
2N/A if (nvlist_lookup_uint64(props, SES_EXP_PROP_SAS_ADDR,
2N/A &sasaddr) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to get prop %s. "
2N/A "continue on for %s %d.", SES_EXP_PROP_SAS_ADDR,
2N/A nodename, instance);
2N/A } else {
2N/A (void) sprintf(sasaddr_str, "%llx", sasaddr);
2N/A
2N/A /* search matching ses_di_node. */
2N/A for (dnode = topo_list_next(&sdp->sed_devs);
2N/A dnode != NULL; dnode = topo_list_next(dnode)) {
2N/A for (i = 0; i < dnode->sdn_target_ports_n;
2N/A i++) {
2N/A if ((dnode->sdn_target_ports[i] !=
2N/A NULL) &&
2N/A (strstr(dnode->sdn_target_ports[i],
2N/A sasaddr_str) != NULL) &&
2N/A dnode->sdn_firm) {
2N/A revision = dnode->sdn_firm;
2N/A topo_mod_dprintf(mod,
2N/A "SAS Expander (%s) rev %s",
2N/A sasaddr_str, revision);
2N/A }
2N/A }
2N/A }
2N/A }
2N/A }
2N/A
2N/A if ((fmri = topo_mod_hcfmri(mod, pnode, FM_HC_SCHEME_VERSION,
2N/A nodename, (topo_instance_t)instance, NULL, auth, part, revision,
2N/A serial)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_mod_hcfmri() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A if ((tn = topo_node_bind(mod, pnode, nodename,
2N/A instance, fmri)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_node_bind() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * For the node label, we look for the following in order:
2N/A *
2N/A * <ses-description>
2N/A * <ses-class-description> <instance>
2N/A * <default-type-label> <instance>
2N/A */
2N/A if (nvlist_lookup_string(props, SES_PROP_DESCRIPTION, &desc) != 0 ||
2N/A desc[0] == '\0') {
2N/A parent = ses_node_parent(np);
2N/A aprops = ses_node_props(parent);
2N/A if (nvlist_lookup_string(aprops, SES_PROP_CLASS_DESCRIPTION,
2N/A &desc) != 0 || desc[0] == '\0')
2N/A desc = (char *)labelname;
2N/A (void) snprintf(label, sizeof (label), "%s %llu", desc,
2N/A instance);
2N/A desc = label;
2N/A }
2N/A
2N/A if (topo_node_label_set(tn, desc, &err) != 0)
2N/A goto error;
2N/A
2N/A if (ses_set_standard_props(mod, frutn, tn, NULL, ses_node_id(np),
2N/A snp->sen_target->set_devpath) != 0)
2N/A goto error;
2N/A
2N/A /*
2N/A * We are adding reported target path using the report bit
2N/A * from SES Enclosure Status page. The SES-2 spec defines
2N/A * the report bit for the Device Slot, SCSI Ports and
2N/A * ESC electronics(controller) element.
2N/A * We care about the controller element to help
2N/A * match the controller label with host device information
2N/A * including SAS address.
2N/A *
2N/A * For SAS enclosure that provides SES Additional Element Status(AES)
2N/A * data for SAS exapander under the controller the SAS expander
2N/A * properties shows the host device information but we need to
2N/A * deal with the case that either no SAS expander element is not
2N/A * supported or SES AES data is not available.
2N/A */
2N/A if (strcmp(nodename, CONTROLLER) == 0) {
2N/A /*
2N/A * Check all alternate nodes and collect the device path
2N/A * of an enclosure target that indicated it manages the
2N/A * controlleri through the report bit.
2N/A */
2N/A for (anp = topo_list_next(&(snp->sen_alt_nodes)); anp != NULL;
2N/A anp = topo_list_next(anp)) {
2N/A if (nvlist_lookup_boolean_value(ses_node_props(
2N/A anp->san_node), SES_PROP_REPORT, &report) != 0 ||
2N/A !report)
2N/A continue;
2N/A
2N/A /*
2N/A * Found an alternate node with report bit set.
2N/A * Note that the string array is used to capture
2N/A * reported target path since there may be multiple
2N/A * enclosure targets in a controller.
2N/A */
2N/A rt_count++;
2N/A }
2N/A
2N/A topo_mod_dprintf(mod,
2N/A "Reported target count %d", rt_count);
2N/A
2N/A if (rt_count) {
2N/A rt_paths = alloca(rt_count * sizeof (char *));
2N/A
2N/A for (anp = topo_list_next(&(snp->sen_alt_nodes)), i = 0;
2N/A anp != NULL && i < rt_count;
2N/A anp = topo_list_next(anp)) {
2N/A if (nvlist_lookup_boolean_value(ses_node_props(
2N/A anp->san_node),
2N/A SES_PROP_REPORT, &report) != 0 || !report)
2N/A continue;
2N/A
2N/A topo_mod_dprintf(mod,
2N/A "Reported target path(index %d): %s.", i,
2N/A anp->san_target->set_devpath);
2N/A rt_paths[i++] = anp->san_target->set_devpath;
2N/A }
2N/A
2N/A /*
2N/A * There should be at least one reported target for
2N/A * the controller. In oder to avoid termination
2N/A * due to missing reported target we create the prop
2N/A * only when the reported target exists.
2N/A * When no reported target prop exists on the topo
2N/A * controller node it should be considered as an error.
2N/A */
2N/A if (topo_prop_set_string_array(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_REPORTED_TARGET_PATHS,
2N/A TOPO_PROP_IMMUTABLE,
2N/A (const char **)rt_paths, rt_count, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to create property %s: %s\n",
2N/A TOPO_PROP_REPORTED_TARGET_PATHS,
2N/A topo_strerror(err));
2N/A goto error;
2N/A }
2N/A }
2N/A }
2N/A
2N/A if (strcmp(nodename, BAY) == 0) {
2N/A if (ses_add_bay_props(mod, tn, snp) != 0)
2N/A goto error;
2N/A
2N/A if (ses_create_disk(sdp, tn, props) != 0)
2N/A goto error;
2N/A
2N/A if (topo_method_register(mod, tn, ses_bay_methods) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_method_register() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A } else if ((strcmp(nodename, FAN) == 0) ||
2N/A (strcmp(nodename, PSU) == 0) ||
2N/A (strcmp(nodename, CONTROLLER) == 0) ||
2N/A (strcmp(nodename, FANMODULE) == 0)) {
2N/A /*
2N/A * Only fan, psu, and controller nodes have a 'present' method.
2N/A * Bay nodes are always present, and disk nodes are present by
2N/A * virtue of being enumerated and SAS expander nodes and
2N/A * SAS connector nodes are also always present once
2N/A * the parent controller is found.
2N/A */
2N/A if (topo_method_register(mod, tn, ses_component_methods) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_method_register() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A }
2N/A
2N/A /* check the facility mangement setting. */
2N/A if (ses_check_facility_mgmt(mod, cp, tn, props) != 0)
2N/A goto error;
2N/A
2N/A snp->sen_target->set_refcount++;
2N/A topo_node_setspecific(tn, snp->sen_target);
2N/A
2N/A nvlist_free(auth);
2N/A nvlist_free(fmri);
2N/A if (node != NULL) *node = tn;
2N/A return (0);
2N/A
2N/Aerror:
2N/A nvlist_free(auth);
2N/A nvlist_free(fmri);
2N/A return (-1);
2N/A}
2N/A
2N/A/*
2N/A * Create SAS expander specific props.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_set_expander_props(ses_enum_data_t *sdp, ses_enum_node_t *snp,
2N/A tnode_t *ptnode, tnode_t *tnode, int *phycount, int64_t *connlist)
2N/A{
2N/A ses_node_t *np = snp->sen_node;
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A nvlist_t *auth = NULL, *fmri = NULL;
2N/A nvlist_t *props, **phylist;
2N/A int err, i;
2N/A uint_t pcount, lcount;
2N/A uint64_t sasaddr, connidx;
2N/A char sasaddr_str[17];
2N/A boolean_t found = B_FALSE, ses_found = B_FALSE;
2N/A ses_di_node_t *dnode, *sesdnode;
2N/A char **lpaths_smp, **lpaths_ses;
2N/A
2N/A props = ses_node_props(np);
2N/A
2N/A /*
2N/A * the uninstalled expander is not enumerated by checking
2N/A * the element status code. No present present' method provided.
2N/A */
2N/A /*
2N/A * Get the Expander SAS address. It should exist.
2N/A */
2N/A if (nvlist_lookup_uint64(props, SES_EXP_PROP_SAS_ADDR,
2N/A &sasaddr) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "Failed to get prop %s.", SES_EXP_PROP_SAS_ADDR);
2N/A goto error;
2N/A }
2N/A
2N/A (void) sprintf(sasaddr_str, "%llx", sasaddr);
2N/A
2N/A /* search matching ses_di_node. */
2N/A for (dnode = topo_list_next(&sdp->sed_devs); dnode != NULL;
2N/A dnode = topo_list_next(dnode)) {
2N/A for (i = 0; i < dnode->sdn_target_ports_n; i++) {
2N/A if (dnode->sdn_target_ports[i] &&
2N/A strstr(dnode->sdn_target_ports[i], sasaddr_str)) {
2N/A found = B_TRUE;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (found)
2N/A break;
2N/A }
2N/A
2N/A if (!found) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_set_expander_props: Failed to find matching "
2N/A "devinfo node for Expander SAS address %s",
2N/A sasaddr_str);
2N/A /* continue on to get storage group props. */
2N/A } else {
2N/A /* create/set the devfs-path and devid in the smp group */
2N/A if (topo_pgroup_create(tnode, &smp_pgroup, &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "failed to create smp property group %s\n",
2N/A topo_strerror(err));
2N/A goto error;
2N/A } else {
2N/A if ((i < dnode->sdn_target_ports_n) &&
2N/A dnode->sdn_target_ports[i] &&
2N/A topo_prop_set_string(tnode, TOPO_PGROUP_SMP,
2N/A TOPO_PROP_SMP_TARGET_PORT, TOPO_PROP_IMMUTABLE,
2N/A dnode->sdn_target_ports[i], &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set %S error %s\n", TOPO_PROP_SAS_ADDR,
2N/A topo_strerror(err));
2N/A }
2N/A if (dnode->sdn_pathdevs &&
2N/A dnode->sdn_pathdevs[0].spd_dpath &&
2N/A topo_prop_set_string(tnode, TOPO_PGROUP_SMP,
2N/A TOPO_PROP_SMP_DEV_PATH, TOPO_PROP_IMMUTABLE,
2N/A dnode->sdn_pathdevs[0].spd_dpath, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set dev error %s\n", topo_strerror(err));
2N/A }
2N/A if (dnode->sdn_devid &&
2N/A topo_prop_set_string(tnode, TOPO_PGROUP_SMP,
2N/A TOPO_PROP_SMP_DEVID, TOPO_PROP_IMMUTABLE,
2N/A dnode->sdn_devid, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set devid error %s\n", topo_strerror(err));
2N/A }
2N/A if (dnode->sdn_ppaths_n &&
2N/A topo_prop_set_string_array(tnode, TOPO_PGROUP_SMP,
2N/A TOPO_PROP_SMP_PHYS_PATH, TOPO_PROP_IMMUTABLE,
2N/A (const char **)dnode->sdn_ppaths,
2N/A dnode->sdn_ppaths_n, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set phys-path error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A
2N/A /* count number of devlinks for this device. */
2N/A for (i = 0, lcount = 0; i < dnode->sdn_pathdev_n; i++) {
2N/A if (dnode->sdn_pathdevs[i].spd_lpath)
2N/A lcount++;
2N/A }
2N/A
2N/A lpaths_smp = alloca(lcount * sizeof (char *));
2N/A
2N/A /* construst devlink array. */
2N/A for (i = 0; i < lcount; i++) {
2N/A if (dnode->sdn_pathdevs[i].spd_lpath)
2N/A lpaths_smp[i] =
2N/A dnode->sdn_pathdevs[i].spd_lpath;
2N/A }
2N/A
2N/A if (lcount &&
2N/A topo_prop_set_string_array(tnode, TOPO_PGROUP_SMP,
2N/A TOPO_PROP_SMP_DEV_LINK, TOPO_PROP_IMMUTABLE,
2N/A (const char **)lpaths_smp, lcount, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set smp devfs-link error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* update the ses property group with SES target info */
2N/A if ((topo_pgroup_create(tnode, &ses_pgroup, &err) != 0) &&
2N/A (err != ETOPO_PROP_DEFD)) {
2N/A /* SES prop group doesn't exist but failed to be created. */
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "ses pgroup create error %s\n", topo_strerror(err));
2N/A goto error;
2N/A } else {
2N/A /* locate assciated enclosure ses_di_node. */
2N/A for (sesdnode = topo_list_next(&sdp->sed_devs);
2N/A sesdnode != NULL; sesdnode = topo_list_next(sesdnode)) {
2N/A for (i = 0; i < sesdnode->sdn_attached_ports_n; i++) {
2N/A /*
2N/A * check if attached port exists and
2N/A * its node type is enclosure and
2N/A * attached port is same as sas address of
2N/A * the expander and
2N/A * bridge port for virtual phy indication
2N/A * exist.
2N/A */
2N/A if (sesdnode->sdn_attached_ports[i] &&
2N/A (sesdnode->sdn_dtype == DTYPE_ESI) &&
2N/A strstr(sesdnode->sdn_attached_ports[i],
2N/A sasaddr_str) &&
2N/A (i < sesdnode->sdn_bridge_ports_n) &&
2N/A sesdnode->sdn_bridge_ports[i]) {
2N/A ses_found = B_TRUE;
2N/A break;
2N/A }
2N/A }
2N/A if (ses_found)
2N/A break;
2N/A }
2N/A
2N/A if (!ses_found) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_set_expander_props: Failed to find attached "
2N/A "port for Exapnder SAS address %s",
2N/A sasaddr_str);
2N/A } else {
2N/A if (topo_prop_set_string(tnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SES_TARGET_PORT, TOPO_PROP_IMMUTABLE,
2N/A sesdnode->sdn_target_ports[i], &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set ses %S error %s\n", TOPO_PROP_SAS_ADDR,
2N/A topo_strerror(err));
2N/A }
2N/A if (sesdnode->sdn_pathdev_n &&
2N/A sesdnode->sdn_pathdevs[0].spd_dpath &&
2N/A topo_prop_set_string(tnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SES_DEV_PATH, TOPO_PROP_IMMUTABLE,
2N/A sesdnode->sdn_pathdevs[0].spd_dpath, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set ses dev error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A if (sesdnode->sdn_devid &&
2N/A topo_prop_set_string(tnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SES_DEVID, TOPO_PROP_IMMUTABLE,
2N/A sesdnode->sdn_devid, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set ses devid error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A if (sesdnode->sdn_ppaths_n &&
2N/A topo_prop_set_string_array(tnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SES_PHYS_PATH, TOPO_PROP_IMMUTABLE,
2N/A (const char **)sesdnode->sdn_ppaths,
2N/A sesdnode->sdn_ppaths_n, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set ses phys-path error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A
2N/A /* count number of devlinks for this device. */
2N/A for (i = 0, lcount = 0; i < sesdnode->sdn_pathdev_n;
2N/A i++) {
2N/A if (sesdnode->sdn_pathdevs[i].spd_lpath)
2N/A lcount++;
2N/A }
2N/A
2N/A lpaths_ses = alloca(lcount * sizeof (char *));
2N/A
2N/A /* construct devlink array. */
2N/A for (i = 0; i < lcount; i++) {
2N/A if (sesdnode->sdn_pathdevs[i].spd_lpath)
2N/A lpaths_ses[i] =
2N/A sesdnode->sdn_pathdevs[i].spd_lpath;
2N/A }
2N/A
2N/A if (lcount &&
2N/A topo_prop_set_string_array(tnode, TOPO_PGROUP_SES,
2N/A TOPO_PROP_SES_DEV_LINK, TOPO_PROP_IMMUTABLE,
2N/A (const char **)lpaths_ses, lcount, &err)) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set ses devfs-link error %s\n",
2N/A topo_strerror(err));
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* create the storage group */
2N/A if (topo_pgroup_create(tnode, &storage_pgroup, &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "create storage error %s\n", topo_strerror(err));
2N/A goto error;
2N/A } else {
2N/A /* set the SAS address prop out of expander element status. */
2N/A if (topo_prop_set_string(tnode, TOPO_PGROUP_STORAGE,
2N/A TOPO_PROP_SAS_ADDR, TOPO_PROP_IMMUTABLE, sasaddr_str,
2N/A &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set %S error %s\n", TOPO_PROP_SAS_ADDR,
2N/A topo_strerror(err));
2N/A }
2N/A
2N/A /* Get the phy information for the expander */
2N/A if (nvlist_lookup_nvlist_array(props, SES_SAS_PROP_PHYS,
2N/A &phylist, &pcount) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "Failed to get prop %s.", SES_SAS_PROP_PHYS);
2N/A } else {
2N/A /*
2N/A * For each phy, get the connector element index and
2N/A * stores into connector element index array.
2N/A */
2N/A *phycount = pcount;
2N/A for (i = 0; i < pcount; i++) {
2N/A if (nvlist_lookup_uint64(phylist[i],
2N/A SES_PROP_CE_IDX, &connidx) == 0) {
2N/A if (connidx != 0xff) {
2N/A connlist[i] = connidx;
2N/A } else {
2N/A connlist[i] = -1;
2N/A }
2N/A } else {
2N/A /* Fail to get the index. set to -1. */
2N/A connlist[i] = -1;
2N/A }
2N/A }
2N/A
2N/A /* set the phy count prop of the expander. */
2N/A if (topo_prop_set_uint64(tnode, TOPO_PGROUP_STORAGE,
2N/A TOPO_PROP_PHY_COUNT, TOPO_PROP_IMMUTABLE, pcount,
2N/A &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set %S error %s\n", TOPO_PROP_PHY_COUNT,
2N/A topo_strerror(err));
2N/A }
2N/A
2N/A /*
2N/A * set the connector element index of
2N/A * the expander phys.
2N/A */
2N/A }
2N/A
2N/A /* populate other misc storage group properties */
2N/A if (found) {
2N/A if (dnode->sdn_mfg && topo_prop_set_string(tnode,
2N/A TOPO_PGROUP_STORAGE, TOPO_STORAGE_MANUFACTURER,
2N/A TOPO_PROP_IMMUTABLE, dnode->sdn_mfg, &err))
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set mfg error %s\n", topo_strerror(err));
2N/A
2N/A if (dnode->sdn_model && topo_prop_set_string(tnode,
2N/A TOPO_PGROUP_STORAGE, TOPO_STORAGE_MODEL,
2N/A TOPO_PROP_IMMUTABLE, dnode->sdn_model, &err))
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set model error %s\n", topo_strerror(err));
2N/A
2N/A if (dnode->sdn_serial && topo_prop_set_string(tnode,
2N/A TOPO_PGROUP_STORAGE, TOPO_STORAGE_SERIAL_NUM,
2N/A TOPO_PROP_IMMUTABLE, dnode->sdn_serial, &err))
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set serial error %s\n",
2N/A topo_strerror(err));
2N/A
2N/A if (dnode->sdn_firm && topo_prop_set_string(tnode,
2N/A TOPO_PGROUP_STORAGE, TOPO_STORAGE_FIRMWARE_REV,
2N/A TOPO_PROP_IMMUTABLE, dnode->sdn_firm, &err))
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set firm error %s\n", topo_strerror(err));
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A
2N/Aerror:
2N/A nvlist_free(auth);
2N/A nvlist_free(fmri);
2N/A return (-1);
2N/A}
2N/A
2N/A/*
2N/A * Create SAS expander specific props.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_set_connector_props(ses_enum_data_t *sdp, ses_enum_node_t *snp,
2N/A tnode_t *tnode, int64_t phy_mask)
2N/A{
2N/A ses_node_t *np = snp->sen_node;
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A nvlist_t *props;
2N/A int err, i;
2N/A uint64_t conntype;
2N/A char phymask_str[17], *conntype_str;
2N/A boolean_t found;
2N/A
2N/A props = ses_node_props(np);
2N/A
2N/A /*
2N/A * convert phy mask to string.
2N/A */
2N/A (void) snprintf(phymask_str, 17, "%llx", phy_mask);
2N/A
2N/A /* create the storage group */
2N/A if (topo_pgroup_create(tnode, &storage_pgroup, &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "create storage error %s\n", topo_strerror(err));
2N/A return (-1);
2N/A } else {
2N/A /* set the SAS address prop of the expander. */
2N/A if (topo_prop_set_string(tnode, TOPO_PGROUP_STORAGE,
2N/A TOPO_STORAGE_SAS_PHY_MASK, TOPO_PROP_IMMUTABLE,
2N/A phymask_str, &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set %S error %s\n", TOPO_STORAGE_SAS_PHY_MASK,
2N/A topo_strerror(err));
2N/A }
2N/A
2N/A /* Get the connector type information for the expander */
2N/A if (nvlist_lookup_uint64(props,
2N/A SES_SC_PROP_CONNECTOR_TYPE, &conntype) != 0) {
2N/A topo_mod_dprintf(mod, "Failed to get prop %s.",
2N/A TOPO_STORAGE_SAS_PHY_MASK);
2N/A } else {
2N/A found = B_FALSE;
2N/A for (i = 0; ; i++) {
2N/A if (sas_connector_type_list[i].sct_type ==
2N/A SAS_CONNECTOR_TYPE_CODE_NOT_DEFINED) {
2N/A break;
2N/A }
2N/A if (sas_connector_type_list[i].sct_type ==
2N/A conntype) {
2N/A conntype_str =
2N/A sas_connector_type_list[i].sct_name;
2N/A found = B_TRUE;
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (!found) {
2N/A if (conntype <
2N/A SAS_CONNECTOR_TYPE_CODE_NOT_DEFINED) {
2N/A conntype_str =
2N/A SAS_CONNECTOR_TYPE_RESERVED;
2N/A } else {
2N/A conntype_str =
2N/A SAS_CONNECTOR_TYPE_NOT_DEFINED;
2N/A }
2N/A }
2N/A
2N/A /* set the phy count prop of the expander. */
2N/A if (topo_prop_set_string(tnode, TOPO_PGROUP_STORAGE,
2N/A TOPO_STORAGE_SAS_CONNECTOR_TYPE,
2N/A TOPO_PROP_IMMUTABLE, conntype_str, &err) != 0) {
2N/A topo_mod_dprintf(mod, "ses_set_expander_props: "
2N/A "set %S error %s\n", TOPO_PROP_PHY_COUNT,
2N/A topo_strerror(err));
2N/A }
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate SAS expander nodes for a given ESC Electronics node(controller)
2N/A * nodes.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_create_esc_sasspecific(ses_enum_data_t *sdp, ses_enum_node_t *snp,
2N/A tnode_t *pnode, ses_enum_chassis_t *cp,
2N/A boolean_t dorange)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A tnode_t *exptn, *contn;
2N/A boolean_t found;
2N/A sas_connector_phy_data_t connectors[64] = {NULL};
2N/A uint64_t max;
2N/A ses_enum_node_t *ctlsnp, *xsnp, *consnp;
2N/A ses_node_t *np = snp->sen_node;
2N/A nvlist_t *props, *psprops;
2N/A uint64_t index, psindex, conindex, psstatus, i, j, count;
2N/A int64_t cidxlist[256] = {NULL};
2N/A int phycount;
2N/A
2N/A props = ses_node_props(np);
2N/A
2N/A if (nvlist_lookup_uint64(props, SES_PROP_ELEMENT_ONLY_INDEX,
2N/A &index) != 0)
2N/A return (-1);
2N/A
2N/A /*
2N/A * For SES constroller node, check to see if there are
2N/A * associated SAS expanders.
2N/A */
2N/A found = B_FALSE;
2N/A max = 0;
2N/A for (ctlsnp = topo_list_next(&cp->sec_nodes); ctlsnp != NULL;
2N/A ctlsnp = topo_list_next(ctlsnp)) {
2N/A if (ctlsnp->sen_type == SES_ET_SAS_EXPANDER) {
2N/A found = B_TRUE;
2N/A if (ctlsnp->sen_instance > max)
2N/A max = ctlsnp->sen_instance;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * No SAS expander found notthing to process.
2N/A */
2N/A if (!found)
2N/A return (0);
2N/A
2N/A topo_mod_dprintf(mod, "%s Controller %d: creating "
2N/A "%llu %s nodes", cp->sec_csn, index, max + 1, SASEXPANDER);
2N/A
2N/A /*
2N/A * The max number represent the number of elements
2N/A * deducted from the highest SES_PROP_ELEMENT_CLASS_INDEX
2N/A * of SET_ET_SAS_EXPANDER type element.
2N/A *
2N/A * There may be multiple ESC Electronics element(controllers)
2N/A * within JBOD(typicall two for redundancy) and SAS expander
2N/A * elements are associated with only one of them. We are
2N/A * still creating the range based max number here.
2N/A * That will cover the case that all expanders are associated
2N/A * with one SES controller.
2N/A */
2N/A if (dorange && topo_node_range_create(mod, pnode,
2N/A SASEXPANDER, 0, max) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A /*
2N/A * Search exapnders with the parent index matching with
2N/A * ESC Electronics element index.
2N/A * Note the index used here is a global index across
2N/A * SES elements.
2N/A */
2N/A for (xsnp = topo_list_next(&cp->sec_nodes); xsnp != NULL;
2N/A xsnp = topo_list_next(xsnp)) {
2N/A if (xsnp->sen_type == SES_ET_SAS_EXPANDER) {
2N/A /*
2N/A * get the parent ESC controller.
2N/A */
2N/A psprops = ses_node_props(xsnp->sen_node);
2N/A if (nvlist_lookup_uint64(psprops,
2N/A SES_PROP_STATUS_CODE, &psstatus) == 0) {
2N/A if (psstatus == SES_ESC_NOT_INSTALLED) {
2N/A /*
2N/A * Not installed.
2N/A * Don't create a ndoe.
2N/A */
2N/A continue;
2N/A }
2N/A } else {
2N/A /*
2N/A * The element should have status code.
2N/A * If not there is no way to find
2N/A * out if the expander element exist or
2N/A * not.
2N/A */
2N/A continue;
2N/A }
2N/A
2N/A /* Get the physical parent index to compare. */
2N/A if (nvlist_lookup_uint64(psprops,
2N/A LIBSES_PROP_PHYS_PARENT, &psindex) == 0) {
2N/A if (index == psindex) {
2N/A /* indentation moved forward */
2N/A /*
2N/A * Handle basic node information of SAS expander
2N/A * element - binding to parent node and
2N/A * allocating FMRI...
2N/A */
2N/A if (ses_create_generic(sdp, cp, xsnp, pnode, pnode, SASEXPANDER,
2N/A "SAS-EXPANDER", &exptn) != 0)
2N/A continue;
2N/A /*
2N/A * Now handle SAS expander unique portion of node creation.
2N/A * The max nubmer of the phy count is 256 since SES-2
2N/A * defines as 1 byte field. The cidxlist has the same
2N/A * number of elements.
2N/A *
2N/A * We use size 64 array to store the connectors.
2N/A * Typically a connectors associated with 4 phys so that
2N/A * matches with the max number of connecters associated
2N/A * with an expander.
2N/A * The phy count goes up to 38 for Sun supported
2N/A * JBOD.
2N/A */
2N/A (void) memset(cidxlist, 0, sizeof (int64_t) * 64);
2N/A if (ses_set_expander_props(sdp, xsnp, pnode, exptn, &phycount,
2N/A cidxlist) != 0) {
2N/A /*
2N/A * error on getting specific prop failed.
2N/A * continue on. Note that the node is
2N/A * left bound.
2N/A */
2N/A continue;
2N/A }
2N/A
2N/A /*
2N/A * count represetns the number of connectors discovered so far.
2N/A */
2N/A count = 0;
2N/A (void) memset(connectors, 0,
2N/A sizeof (sas_connector_phy_data_t) * 64);
2N/A for (i = 0; i < phycount; i++) {
2N/A if (cidxlist[i] != -1) {
2N/A /* connector index is valid. */
2N/A for (j = 0; j < count; j++) {
2N/A if (connectors[j].scpd_index ==
2N/A cidxlist[i]) {
2N/A /*
2N/A * Just update phy mask.
2N/A * The postion for connector
2N/A * index lists(cidxlist index)
2N/A * is set.
2N/A */
2N/A connectors[j].scpd_pm =
2N/A connectors[j].scpd_pm |
2N/A (1ULL << i);
2N/A break;
2N/A }
2N/A }
2N/A /*
2N/A * If j and count matche a new connector
2N/A * index is found.
2N/A */
2N/A if (j == count) {
2N/A /* add a new index and phy mask. */
2N/A connectors[count].scpd_index =
2N/A cidxlist[i];
2N/A connectors[count].scpd_pm =
2N/A connectors[count].scpd_pm |
2N/A (1ULL << i);
2N/A count++;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * create range for the connector nodes.
2N/A * The class index of the ses connector element
2N/A * is set as the instance nubmer for the node.
2N/A * Even though one expander may not have all connectors
2N/A * are associated with we are creating the range with
2N/A * max possible instance number.
2N/A */
2N/A found = B_FALSE;
2N/A max = 0;
2N/A for (consnp = topo_list_next(&cp->sec_nodes);
2N/A consnp != NULL; consnp = topo_list_next(consnp)) {
2N/A if (consnp->sen_type == SES_ET_SAS_CONNECTOR) {
2N/A psprops = ses_node_props(consnp->sen_node);
2N/A found = B_TRUE;
2N/A if (consnp->sen_instance > max)
2N/A max = consnp->sen_instance;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * No SAS connector found nothing to process.
2N/A */
2N/A if (!found)
2N/A return (0);
2N/A
2N/A if (dorange && topo_node_range_create(mod, exptn,
2N/A RECEPTACLE, 0, max) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A /* search matching connector element using the index. */
2N/A for (i = 0; i < count; i++) {
2N/A found = B_FALSE;
2N/A for (consnp = topo_list_next(&cp->sec_nodes);
2N/A consnp != NULL; consnp = topo_list_next(consnp)) {
2N/A if (consnp->sen_type == SES_ET_SAS_CONNECTOR) {
2N/A psprops = ses_node_props(
2N/A consnp->sen_node);
2N/A /*
2N/A * Get the physical parent index to
2N/A * compare.
2N/A * The connector elements are children
2N/A * of ESC Electronics element even
2N/A * though we enumerate them under
2N/A * an expander in libtopo.
2N/A */
2N/A if (nvlist_lookup_uint64(psprops,
2N/A SES_PROP_ELEMENT_ONLY_INDEX,
2N/A &conindex) == 0) {
2N/A if (conindex ==
2N/A connectors[i].scpd_index) {
2N/A found = B_TRUE;
2N/A break;
2N/A }
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* now create a libtopo node. */
2N/A if (found) {
2N/A /* Create generic props. */
2N/A if (ses_create_generic(sdp, cp, consnp, exptn,
2N/A topo_node_parent(exptn),
2N/A RECEPTACLE, "RECEPTACLE", &contn) !=
2N/A 0) {
2N/A continue;
2N/A }
2N/A /* Create connector specific props. */
2N/A if (ses_set_connector_props(sdp, consnp,
2N/A contn, connectors[i].scpd_pm) != 0) {
2N/A continue;
2N/A }
2N/A }
2N/A }
2N/A /* end indentation change */
2N/A }
2N/A }
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate any protocol specific portion of a node.
2N/A */
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_create_protocol_specific(ses_enum_data_t *sdp, ses_enum_node_t *snp,
2N/A tnode_t *pnode, uint64_t type, ses_enum_chassis_t *cp,
2N/A boolean_t dorange)
2N/A{
2N/A
2N/A if (type == SES_ET_ESC_ELECTRONICS) {
2N/A /* create SAS specific children(expanders and connectors. */
2N/A return (ses_create_esc_sasspecific(sdp, snp, pnode, cp,
2N/A dorange));
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate any children of a given type.
2N/A */
2N/Astatic int
2N/Ases_create_children(ses_enum_data_t *sdp, tnode_t *pnode, uint64_t type,
2N/A const char *nodename, const char *defaultlabel, ses_enum_chassis_t *cp,
2N/A boolean_t dorange)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A boolean_t found;
2N/A uint64_t max;
2N/A ses_enum_node_t *snp;
2N/A tnode_t *tn;
2N/A
2N/A /*
2N/A * First go through and count how many matching nodes we have.
2N/A */
2N/A max = 0;
2N/A found = B_FALSE;
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == type) {
2N/A found = B_TRUE;
2N/A if (snp->sen_instance > max)
2N/A max = snp->sen_instance;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * No enclosure should export both DEVICE and ARRAY_DEVICE elements.
2N/A * Since we map both of these to 'disk', if an enclosure does this, we
2N/A * just ignore the array elements.
2N/A */
2N/A if (!found ||
2N/A (type == SES_ET_ARRAY_DEVICE && cp->sec_hasdev))
2N/A return (0);
2N/A
2N/A topo_mod_dprintf(mod, "%s: creating %llu %s nodes",
2N/A cp->sec_csn, max + 1, nodename);
2N/A
2N/A if (dorange && topo_node_range_create(mod, pnode,
2N/A nodename, 0, max) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == type) {
2N/A /*
2N/A * With flat layout of ses nodes there is no
2N/A * way to find out the direct FRU for a node.
2N/A * Passing NULL for fru topo node. Note that
2N/A * ses_create_children_from_phys_tree() provides
2N/A * the actual direct FRU for a node.
2N/A */
2N/A if (ses_create_generic(sdp, cp, snp, pnode, NULL,
2N/A nodename, defaultlabel, &tn) != 0)
2N/A return (-1);
2N/A /*
2N/A * For some SES element there may be protocol specific
2N/A * information to process. Here we are processing
2N/A * the association between enclosure controller and
2N/A * SAS expanders.
2N/A */
2N/A if (type == SES_ET_ESC_ELECTRONICS) {
2N/A /* create SAS expander node */
2N/A if (ses_create_protocol_specific(sdp, snp,
2N/A tn, type, cp, dorange) != 0) {
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A }
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate a new subchassis instance in the topology.
2N/A */
2N/Astatic int
2N/Ases_create_subchassis(ses_enum_data_t *sdp, tnode_t *pnode,
2N/A ses_enum_chassis_t *scp)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A tnode_t *tn;
2N/A nvlist_t *props;
2N/A nvlist_t *auth = NULL, *fmri = NULL;
2N/A uint64_t instance = scp->sec_instance;
2N/A char *desc;
2N/A char label[128];
2N/A char **paths;
2N/A int i, err;
2N/A ses_enum_target_t *stp;
2N/A int ret = -1;
2N/A
2N/A /*
2N/A * Copy authority information from parent enclosure node
2N/A */
2N/A if ((auth = topo_mod_auth(mod, pnode)) == NULL)
2N/A goto error;
2N/A
2N/A /*
2N/A * Record the subchassis serial number in the FMRI.
2N/A * For now, we assume that logical id is the subchassis serial number.
2N/A * If this assumption changes in future, then the following
2N/A * piece of code will need to be updated via an RFE.
2N/A */
2N/A if ((fmri = topo_mod_hcfmri(mod, pnode, FM_HC_SCHEME_VERSION,
2N/A SUBCHASSIS, (topo_instance_t)instance, NULL, auth, NULL, NULL,
2N/A NULL)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_mod_hcfmri() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A if ((tn = topo_node_bind(mod, pnode, SUBCHASSIS,
2N/A instance, fmri)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_node_bind() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A props = ses_node_props(scp->sec_enclosure);
2N/A
2N/A /*
2N/A * Look for the subchassis label in the following order:
2N/A * <ses-description>
2N/A * <ses-class-description> <instance>
2N/A * <default-type-label> <instance>
2N/A *
2N/A * For subchassis, the default label is "SUBCHASSIS"
2N/A */
2N/A if (nvlist_lookup_string(props, SES_PROP_DESCRIPTION, &desc) != 0 ||
2N/A desc[0] == '\0') {
2N/A if (nvlist_lookup_string(props, SES_PROP_CLASS_DESCRIPTION,
2N/A &desc) == 0 && desc[0] != '\0')
2N/A (void) snprintf(label, sizeof (label), "%s %llu", desc,
2N/A instance);
2N/A else
2N/A (void) snprintf(label, sizeof (label),
2N/A "SUBCHASSIS %llu", instance);
2N/A desc = label;
2N/A }
2N/A
2N/A if (topo_node_label_set(tn, desc, &err) != 0)
2N/A goto error;
2N/A
2N/A if (ses_set_standard_props(mod, NULL, tn, NULL,
2N/A ses_node_id(scp->sec_enclosure), scp->sec_target->set_devpath) != 0)
2N/A goto error;
2N/A
2N/A if (ses_check_facility_mgmt(mod, scp, tn, props) != 0)
2N/A goto error;
2N/A
2N/A /*
2N/A * Set the 'chassis-type' property for this subchassis. This is either
2N/A * 'ses-class-description' or 'subchassis'.
2N/A */
2N/A if (nvlist_lookup_string(props, SES_PROP_CLASS_DESCRIPTION, &desc) != 0)
2N/A desc = "subchassis";
2N/A
2N/A if (topo_prop_set_string(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_CHASSIS_TYPE, TOPO_PROP_IMMUTABLE, desc, &err) != 0) {
2N/A topo_mod_dprintf(mod, "failed to create property %s: %s\n",
2N/A TOPO_PROP_CHASSIS_TYPE, topo_strerror(err));
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * For enclosures, we want to include all possible targets (for upgrade
2N/A * purposes).
2N/A */
2N/A for (i = 0, stp = topo_list_next(&scp->sec_targets); stp != NULL;
2N/A stp = topo_list_next(stp), i++)
2N/A ;
2N/A
2N/A verify(i != 0);
2N/A paths = alloca(i * sizeof (char *));
2N/A
2N/A for (i = 0, stp = topo_list_next(&scp->sec_targets); stp != NULL;
2N/A stp = topo_list_next(stp), i++)
2N/A paths[i] = stp->set_devpath;
2N/A
2N/A if (topo_prop_set_string_array(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_PATHS, TOPO_PROP_IMMUTABLE, (const char **)paths,
2N/A i, &err) != 0) {
2N/A topo_mod_dprintf(mod, "failed to create property %s: %s\n",
2N/A TOPO_PROP_PATHS, topo_strerror(err));
2N/A goto error;
2N/A }
2N/A
2N/A if (topo_method_register(mod, tn, ses_enclosure_methods) != 0) {
2N/A topo_mod_dprintf(mod, "topo_method_register() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * Create the nodes for controllers and bays.
2N/A */
2N/A if (ses_create_children(sdp, tn, SES_ET_ESC_ELECTRONICS,
2N/A CONTROLLER, "CONTROLLER", scp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_DEVICE,
2N/A BAY, "BAY", scp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_ARRAY_DEVICE,
2N/A BAY, "BAY", scp, B_TRUE) != 0)
2N/A goto error;
2N/A
2N/A ret = 0;
2N/A
2N/Aerror:
2N/A nvlist_free(auth);
2N/A nvlist_free(fmri);
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * Function we use to insert a node.
2N/A */
2N/Astatic int
2N/Ases_phys_tree_insert(topo_mod_t *mod, ses_phys_tree_t **sproot,
2N/A ses_phys_tree_t *child)
2N/A{
2N/A uint64_t ppindex, eindex, pindex;
2N/A ses_phys_tree_t *node_ptr;
2N/A int ret = 0;
2N/A
2N/A assert(sproot != NULL);
2N/A assert(child != NULL);
2N/A
2N/A if (*sproot == NULL) {
2N/A *sproot = child;
2N/A return (0);
2N/A }
2N/A
2N/A pindex = child->spt_pindex;
2N/A ppindex = (*sproot)->spt_pindex;
2N/A eindex = (*sproot)->spt_eonlyindex;
2N/A
2N/A /*
2N/A * If the element only index of the root is same as the physical
2N/A * parent index of a node to be added, add the node as a child of
2N/A * the current root.
2N/A */
2N/A if (eindex == pindex) {
2N/A (void) ses_phys_tree_insert(mod, &(*sproot)->spt_child, child);
2N/A child->spt_parent = *sproot;
2N/A } else if (ppindex == pindex) {
2N/A /*
2N/A * if the physical parent of the current root and the child
2N/A * is same, then this should be a sibling node.
2N/A * Siblings can be different element types and arrange
2N/A * them by group.
2N/A */
2N/A if ((*sproot)->spt_senumnode->sen_type ==
2N/A child->spt_senumnode->sen_type) {
2N/A child->spt_sibling = *sproot;
2N/A *sproot = child;
2N/A } else {
2N/A /* add a node in front of matching element type. */
2N/A node_ptr = *sproot;
2N/A while (node_ptr->spt_sibling != NULL) {
2N/A if (node_ptr->spt_sibling->
2N/A spt_senumnode->sen_type ==
2N/A child->spt_senumnode->sen_type) {
2N/A child->spt_sibling =
2N/A node_ptr->spt_sibling;
2N/A node_ptr->spt_sibling = child;
2N/A break;
2N/A }
2N/A node_ptr = node_ptr->spt_sibling;
2N/A }
2N/A /* no matching. Add the child at the end. */
2N/A if (node_ptr->spt_sibling == NULL) {
2N/A node_ptr->spt_sibling = child;
2N/A }
2N/A }
2N/A child->spt_parent = (*sproot)->spt_parent;
2N/A } else {
2N/A /*
2N/A * The root and the node is not directly related.
2N/A * Try to insert to the child sub-tree first and then try to
2N/A * insert to the sibling sub-trees. If fails for both
2N/A * the caller will retry insertion later.
2N/A */
2N/A if ((*sproot)->spt_child) {
2N/A ret = ses_phys_tree_insert(mod, &(*sproot)->spt_child,
2N/A child);
2N/A }
2N/A if ((*sproot)->spt_child == NULL || ret != 0) {
2N/A if ((*sproot)->spt_sibling) {
2N/A ret = ses_phys_tree_insert(mod,
2N/A &(*sproot)->spt_sibling, child);
2N/A } else {
2N/A ret = 1;
2N/A }
2N/A }
2N/A return (ret);
2N/A }
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Construct tree view of ses elements through parent phyiscal element index.
2N/A * The root of tree is already constructed using the enclosure element.
2N/A */
2N/Astatic int
2N/Ases_construct_phys_tree(ses_enum_data_t *sdp, ses_enum_chassis_t *cp,
2N/A ses_phys_tree_t *sproot)
2N/A{
2N/A ses_enum_node_t *snp;
2N/A ses_phys_tree_t *child;
2N/A ses_phys_tree_t *u_watch = NULL;
2N/A ses_phys_tree_t *u_head = NULL;
2N/A ses_phys_tree_t *u_tail = NULL;
2N/A int u_inserted = 0, u_left = 0;
2N/A nvlist_t *props;
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if ((child = topo_mod_zalloc(mod,
2N/A sizeof (ses_phys_tree_t))) == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to allocate root.");
2N/A return (-1);
2N/A }
2N/A child->spt_snode = snp->sen_node;
2N/A props = ses_node_props(snp->sen_node);
2N/A if (nvlist_lookup_uint64(props,
2N/A LIBSES_PROP_PHYS_PARENT, &child->spt_pindex) != 0) {
2N/A /*
2N/A * the prop should exist. continue to see if
2N/A * we can build a partial tree with other elements.
2N/A */
2N/A topo_mod_dprintf(mod,
2N/A "ses_construct_phys_tree(): Failed to find prop %s "
2N/A "on ses element type %llu and instance %llu "
2N/A "(CSN %s).", LIBSES_PROP_PHYS_PARENT,
2N/A snp->sen_type, snp->sen_instance, cp->sec_csn ?
2N/A cp->sec_csn : "not known");
2N/A topo_mod_free(mod, child, sizeof (ses_phys_tree_t));
2N/A continue;
2N/A } else {
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_PROP_FRU, &child->spt_isfru) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_construct_phys_tree(): Failed to "
2N/A "find prop %s on ses element type %llu "
2N/A "and instance %llu (CSN %s).",
2N/A LIBSES_PROP_FRU,
2N/A snp->sen_type, snp->sen_instance,
2N/A cp->sec_csn ? cp->sec_csn : "not known");
2N/A /*
2N/A * Ignore if the prop doesn't exist.
2N/A * Note that the enclosure itself should be
2N/A * a FRU so if no FRU found the enclosure FRU
2N/A * can be a direct FRU.
2N/A */
2N/A }
2N/A verify(nvlist_lookup_uint64(props,
2N/A SES_PROP_ELEMENT_ONLY_INDEX,
2N/A &child->spt_eonlyindex) == 0);
2N/A verify(nvlist_lookup_uint64(props,
2N/A SES_PROP_ELEMENT_CLASS_INDEX,
2N/A &child->spt_cindex) == 0);
2N/A }
2N/A child->spt_senumnode = snp;
2N/A if (ses_phys_tree_insert(mod, &sproot, child) != 0) {
2N/A /* collect unresolved element to process later. */
2N/A if (u_head == NULL) {
2N/A u_head = child;
2N/A u_tail = child;
2N/A } else {
2N/A child->spt_sibling = u_head;
2N/A u_head = child;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * The parent of a child node may not be inserted yet.
2N/A * Trying to insert the child until no child is left or
2N/A * no child is not added further. For the latter
2N/A * the hierarchical relationship between elements
2N/A * should be checked through SUNW,FRUID page.
2N/A * u_watch is a watch dog to check the prgress of unresolved
2N/A * node.
2N/A */
2N/A u_watch = u_tail;
2N/A while (u_head) {
2N/A child = u_head;
2N/A u_head = u_head->spt_sibling;
2N/A if (u_head == NULL)
2N/A u_tail = NULL;
2N/A child->spt_sibling = NULL;
2N/A if (ses_phys_tree_insert(mod, &sproot, child) != 0) {
2N/A u_tail->spt_sibling = child;
2N/A u_tail = child;
2N/A if (child == u_watch) {
2N/A /*
2N/A * We just scanned one round for the
2N/A * unresolved list. Check to see whether we
2N/A * have nodes inserted, if none, we should
2N/A * break in case of an indefinite loop.
2N/A */
2N/A if (u_inserted == 0) {
2N/A /*
2N/A * Indicate there is unhandled node.
2N/A * Chain free the whole unsolved
2N/A * list here.
2N/A */
2N/A u_left++;
2N/A break;
2N/A } else {
2N/A u_inserted = 0;
2N/A u_watch = u_tail;
2N/A }
2N/A }
2N/A } else {
2N/A /*
2N/A * We just inserted one rpnode, increment the
2N/A * unsolved_inserted counter. We will utilize this
2N/A * counter to detect an indefinite insertion loop.
2N/A */
2N/A u_inserted++;
2N/A if (child == u_watch) {
2N/A /*
2N/A * watch dog node itself is inserted.
2N/A * Set it to the tail and refresh the watching.
2N/A */
2N/A u_watch = u_tail;
2N/A u_inserted = 0;
2N/A u_left = 0;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* check if there is left out unresolved nodes. */
2N/A if (u_left) {
2N/A topo_mod_dprintf(mod, "ses_construct_phys_tree(): "
2N/A "Failed to construct physical view of the following "
2N/A "ses elements of Chassis (CSN %s).",
2N/A cp->sec_csn ? cp->sec_csn : "not known");
2N/A while (u_head) {
2N/A u_tail = u_head->spt_sibling;
2N/A topo_mod_dprintf(mod,
2N/A "\telement type (%llu) and instance (%llu)",
2N/A u_head->spt_senumnode->sen_type,
2N/A u_head->spt_senumnode->sen_instance);
2N/A topo_mod_free(mod, u_head, sizeof (ses_phys_tree_t));
2N/A u_head = u_tail;
2N/A }
2N/A return (-1);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Free the whole phys tree.
2N/A */
2N/Astatic void ses_phys_tree_free(topo_mod_t *mod, ses_phys_tree_t *sproot)
2N/A{
2N/A if (sproot == NULL)
2N/A return;
2N/A
2N/A /* Free child tree. */
2N/A if (sproot->spt_child) {
2N/A ses_phys_tree_free(mod, sproot->spt_child);
2N/A }
2N/A
2N/A /* Free sibling trees. */
2N/A if (sproot->spt_sibling) {
2N/A ses_phys_tree_free(mod, sproot->spt_sibling);
2N/A }
2N/A
2N/A /* Free root node itself. */
2N/A topo_mod_free(mod, sproot, sizeof (ses_phys_tree_t));
2N/A}
2N/A
2N/A/*
2N/A * Parses phys_enum_type table to get the index of the given type.
2N/A */
2N/Astatic boolean_t
2N/Ais_type_enumerated(ses_phys_tree_t *node, int *index)
2N/A{
2N/A int i;
2N/A
2N/A for (i = 0; i < N_PHYS_ENUM_TYPES; i++) {
2N/A if (node->spt_senumnode->sen_type ==
2N/A phys_enum_type_list[i].pet_type) {
2N/A *index = i;
2N/A return (B_TRUE);
2N/A }
2N/A }
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * Recusrive routine for top-down enumeration of the tree.
2N/A */
2N/Astatic int
2N/Ases_enumerate_node(ses_enum_data_t *sdp, tnode_t *pnode, ses_enum_chassis_t *cp,
2N/A ses_phys_tree_t *parent, int mrange[])
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A ses_phys_tree_t *child = NULL;
2N/A int i, ret = 0, ret_ch;
2N/A uint64_t prevtype = SES_ET_UNSPECIFIED;
2N/A ses_phys_tree_t *dirfru = NULL;
2N/A tnode_t *tn = NULL, *frutn = NULL;
2N/A
2N/A if (parent == NULL) {
2N/A return (0);
2N/A }
2N/A
2N/A for (child = parent->spt_child; child != NULL;
2N/A child = child->spt_sibling) {
2N/A if (is_type_enumerated(child, &i)) {
2N/A if (prevtype != phys_enum_type_list[i].pet_type) {
2N/A /* check if range needs to be created. */
2N/A if (phys_enum_type_list[i].pet_dorange &&
2N/A topo_node_range_create(mod, pnode,
2N/A phys_enum_type_list[i].pet_nodename, 0,
2N/A mrange[i]) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: "
2N/A "%s", topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A prevtype = phys_enum_type_list[i].pet_type;
2N/A }
2N/A
2N/A if (!(child->spt_isfru)) {
2N/A for (dirfru = parent; dirfru != NULL;
2N/A dirfru = dirfru->spt_parent) {
2N/A if (dirfru->spt_isfru) {
2N/A break;
2N/A }
2N/A }
2N/A /* found direct FRU node. */
2N/A if (dirfru) {
2N/A frutn = dirfru->spt_tnode;
2N/A } else {
2N/A frutn = NULL;
2N/A }
2N/A } else {
2N/A frutn = NULL;
2N/A }
2N/A
2N/A if (ses_create_generic(sdp, cp, child->spt_senumnode,
2N/A pnode, frutn, phys_enum_type_list[i].pet_nodename,
2N/A phys_enum_type_list[i].pet_defaultlabel, &tn) != 0)
2N/A return (-1);
2N/A
2N/A child->spt_tnode = tn;
2N/A /*
2N/A * For some SES element there may be protocol specific
2N/A * information to process. Here we are processing
2N/A * the association between enclosure controller and
2N/A * SAS expanders.
2N/A */
2N/A if (phys_enum_type_list[i].pet_type ==
2N/A SES_ET_ESC_ELECTRONICS) {
2N/A /* create SAS expander node */
2N/A if (ses_create_protocol_specific(sdp,
2N/A child->spt_senumnode, tn,
2N/A phys_enum_type_list[i].pet_type,
2N/A cp, phys_enum_type_list[i].pet_dorange) !=
2N/A 0) {
2N/A return (-1);
2N/A }
2N/A }
2N/A } else {
2N/A continue;
2N/A }
2N/A ret_ch = ses_enumerate_node(sdp, tn, cp, child, mrange);
2N/A if (ret_ch)
2N/A ret = ret_ch; /* there was an error and set the ret. */
2N/A }
2N/A
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate types of nodes that are specified in the hierarchy
2N/A * element type list.
2N/A */
2N/Astatic int
2N/Ases_create_children_from_phys_tree(ses_enum_data_t *sdp, tnode_t *pnode,
2N/A ses_enum_chassis_t *cp, ses_phys_tree_t *phys_tree)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A int mrange[N_PHYS_ENUM_TYPES] = { 0 };
2N/A ses_enum_node_t *snp;
2N/A int i, ret;
2N/A
2N/A /*
2N/A * First get max range for each type of element to be enumerated.
2N/A */
2N/A for (i = 0; i < N_PHYS_ENUM_TYPES; i++) {
2N/A if (phys_enum_type_list[i].pet_dorange) {
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type ==
2N/A phys_enum_type_list[i].pet_type) {
2N/A if (snp->sen_instance > mrange[i])
2N/A mrange[i] =
2N/A snp->sen_instance;
2N/A }
2N/A }
2N/A }
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: creating nodes from FRU hierarchy tree.",
2N/A cp->sec_csn);
2N/A
2N/A if ((ret = ses_enumerate_node(sdp, pnode, cp, phys_tree, mrange)) !=
2N/A 0) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_create_children_from_phys_tree() failed: ");
2N/A return (ret);
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A#if defined(__x86)
2N/A
2N/A/*
2N/A * check whether FM_IOC_GENTOPO_LEGACY is set or not.
2N/A *
2N/A * return value: 0 if is set.
2N/A * -1 if fail to check or it is not set.
2N/A */
2N/Astatic int
2N/Acheck_legacy_enum(topo_mod_t *mod, int *legacy)
2N/A{
2N/A int fd, rv;
2N/A char *obuf = NULL, *ibuf = NULL;
2N/A size_t obufsz = 0, ibufsz = 0;
2N/A nvlist_t *nvl = NULL;
2N/A int32_t flag;
2N/A fm_ioc_data_t fid;
2N/A
2N/A fd = open("/dev/fm", O_RDONLY);
2N/A if (fd < 0) {
2N/A topo_mod_dprintf(mod, "failed to open /dev/fm.\n");
2N/A return (-1);
2N/A }
2N/A
2N/A /* set up buffers and ioctl data structure */
2N/A obufsz = FM_IOC_MAXBUFSZ;
2N/A obuf = topo_mod_alloc(mod, obufsz);
2N/A if (obuf == NULL) {
2N/A topo_mod_dprintf(mod, "topo_mod_alloc failed.\n");
2N/A close(fd);
2N/A return (-1);
2N/A }
2N/A
2N/A fid.fid_version = 1;
2N/A fid.fid_insz = ibufsz;
2N/A fid.fid_inbuf = ibuf;
2N/A fid.fid_outsz = obufsz;
2N/A fid.fid_outbuf = obuf;
2N/A
2N/A /* send the ioctl to /dev/fm to retrieve legacy variable */
2N/A rv = ioctl(fd, FM_IOC_GENTOPO_LEGACY, &fid);
2N/A if (rv < 0) {
2N/A topo_mod_dprintf(mod, "ioctl to /dev/fm failed");
2N/A (void) close(fd);
2N/A topo_mod_free(mod, obuf, obufsz);
2N/A return (-1);
2N/A }
2N/A
2N/A (void) close(fd);
2N/A
2N/A (void) nvlist_unpack(fid.fid_outbuf, fid.fid_outsz, &nvl, 0);
2N/A (void) nvlist_lookup_int32(nvl, FM_GENTOPO_LEGACY, &flag);
2N/A
2N/A nvlist_free(nvl);
2N/A topo_mod_free(mod, obuf, obufsz);
2N/A
2N/A /* legacy kernel variable not set. */
2N/A *legacy = flag;
2N/A
2N/A return (0);
2N/A}
2N/A#endif
2N/A
2N/A/*
2N/A * Instantiate internal expander attached drives in the topology.
2N/A *
2N/A * input chassis should represent an internal enclosure.
2N/A * For some platforms both direct attached and expander attached
2N/A * drives may exist and the instance number can be coordinated
2N/A * through max_internal_inst var.
2N/A */
2N/Astatic int
2N/Ases_genenum_internal_drive(ses_enum_data_t *sdp, tnode_t *pnode,
2N/A ses_enum_chassis_t *cp, int *max_internal_inst)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A ses_enum_node_t *snp;
2N/A int max;
2N/A#if defined(__x86)
2N/A int legacy = 0;
2N/A#endif
2N/A boolean_t found;
2N/A
2N/A if (!cp->sec_internal) {
2N/A return (0);
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: check if bays exist in "
2N/A "the given internal enclosure.", cp->sec_csn);
2N/A /*
2N/A * Now enumeratate the bays within the internal enclosure.
2N/A *
2N/A * For x86, verifiy the x86gentopo_legacy should be turned off.
2N/A * When legacy flag is set it is expected that disk map
2N/A * file for internal disk enumeration is provided.
2N/A *
2N/A * Note that direct attached internal disks are not
2N/A * handled here. Those disks are supposed to be handled by x86 gentopo
2N/A * through SMBIOS type 7 OEM record.
2N/A */
2N/A#if defined(__x86)
2N/A if ((check_legacy_enum(mod, &legacy) == 0) && (legacy != 1)) {
2N/A#endif
2N/A max = 0;
2N/A found = B_FALSE;
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if ((snp->sen_type == SES_ET_DEVICE) ||
2N/A (snp->sen_type == SES_ET_ARRAY_DEVICE)) {
2N/A found = B_TRUE;
2N/A if (snp->sen_instance > max)
2N/A max = snp->sen_instance;
2N/A }
2N/A }
2N/A
2N/A if (!found) {
2N/A if (max_internal_inst)
2N/A *max_internal_inst = max;
2N/A topo_mod_dprintf(mod, "%s: no bay is found "
2N/A "within the internal enclosure.",
2N/A cp->sec_csn);
2N/A return (0);
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: creating %llu %s "
2N/A "nodes of an expander attached internal "
2N/A "disks.", cp->sec_csn, max + 1, BAY);
2N/A
2N/A if (topo_node_range_create(mod, pnode,
2N/A BAY, 0, max) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: "
2N/A "%s", topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A for (snp = topo_list_next(&cp->sec_nodes);
2N/A snp != NULL; snp = topo_list_next(snp)) {
2N/A if ((snp->sen_type == SES_ET_DEVICE) ||
2N/A (snp->sen_type == SES_ET_ARRAY_DEVICE)) {
2N/A if (ses_create_generic(sdp, cp, snp, pnode,
2N/A NULL, BAY, "BAY", NULL) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "Internal bay elemnet "
2N/A "creation failed.");
2N/A return (-1);
2N/A }
2N/A
2N/A }
2N/A }
2N/A if (max_internal_inst)
2N/A *max_internal_inst = max;
2N/A
2N/A topo_mod_dprintf(mod, "%s: created %llu %s "
2N/A "nodes of an expander attached internal "
2N/A "disks.", cp->sec_csn, max + 1, BAY);
2N/A
2N/A#if defined(__x86)
2N/A }
2N/A#endif
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Manufacturing strings can contain characters that are invalid for use in hc
2N/A * authority names. This trims leading and trailing whitespace, and
2N/A * substitutes any characters known to be bad.
2N/A */
2N/Achar *
2N/Ases_auth_clean(topo_mod_t *mod, const char *str)
2N/A{
2N/A char *buf, *p;
2N/A
2N/A if (str == NULL)
2N/A return (NULL);
2N/A
2N/A if ((buf = topo_mod_strdup(mod, str)) == NULL)
2N/A return (NULL);
2N/A
2N/A while ((p = strpbrk(buf, " :=")) != NULL)
2N/A *p = '-';
2N/A
2N/A return (buf);
2N/A}
2N/A
2N/A/*
2N/A * Instantiate a new chassis instance in the topology.
2N/A */
2N/Astatic int
2N/Ases_create_chassis(ses_enum_data_t *sdp, tnode_t *pnode, ses_enum_chassis_t *cp)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A nvlist_t *props;
2N/A char *raw_manufacturer, *raw_model, *raw_revision;
2N/A char *manufacturer = NULL, *model = NULL, *product = NULL;
2N/A char *revision = NULL;
2N/A char *serial, *part = NULL;
2N/A char **paths;
2N/A size_t prodlen;
2N/A tnode_t *tn, *systemtn;
2N/A nvlist_t *fmri = NULL, *auth = NULL;
2N/A int ret = -1;
2N/A ses_enum_node_t *snp;
2N/A ses_enum_target_t *stp;
2N/A ses_enum_chassis_t *scp;
2N/A int i, err, max;
2N/A uint64_t sc_count = 0, pindex;
2N/A ses_phys_tree_t *sproot = NULL;
2N/A boolean_t found;
2N/A hrtime_t start;
2N/A hrtime_t end;
2N/A double duration;
2N/A
2N/A if (cp->sec_internal) {
2N/A /*
2N/A * For an internal chassis, no chassis is created.
2N/A * An SAS expander element is enumerated.
2N/A * as a child of the platform chassis to represent
2N/A * internal expander.
2N/A */
2N/A if ((systemtn = topo_node_lookup(pnode, CHASSIS, 0)) == NULL) {
2N/A topo_mod_dprintf(mod, "chassis node with instance 0 "
2N/A "not found.");
2N/A return (0);
2N/A }
2N/A
2N/A /*
2N/A * Count the nubmer of expanders in the internal enclosure.
2N/A */
2N/A max = 0;
2N/A found = B_FALSE;
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == SES_ET_SAS_EXPANDER) {
2N/A found = B_TRUE;
2N/A if (snp->sen_instance > max)
2N/A max = snp->sen_instance;
2N/A }
2N/A }
2N/A
2N/A if (found) {
2N/A topo_mod_dprintf(mod, "%s: creating %llu %s nodes of "
2N/A " an internal SAS expander element",
2N/A cp->sec_csn, max + 1, SASEXPANDER);
2N/A
2N/A if (topo_node_range_create(mod, systemtn,
2N/A SASEXPANDER, 0, max) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A return (-1);
2N/A }
2N/A
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == SES_ET_SAS_EXPANDER) {
2N/A /*
2N/A * Passing NULL for the fru node if the
2N/A * internal enclosure is a FRU so the
2N/A * SAS expander element itself will be
2N/A * reported as a FRU.
2N/A * Othewise set the parent(chassis)
2N/A * node as a FRU.
2N/A */
2N/A if (ses_create_generic(sdp, cp, snp,
2N/A systemtn,
2N/A cp->sec_is_fru ? NULL : systemtn,
2N/A SASEXPANDER, "SAS-EXPANDER",
2N/A NULL) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "Internal SAS expander "
2N/A "elemnet creation failed.");
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A }
2N/A }
2N/A return (0);
2N/A }
2N/A
2N/A /*
2N/A * Check to see if there are any devices presennt in the chassis. If
2N/A * not, ignore the chassis alltogether. This is most useful for
2N/A * ignoring internal HBAs that present a SES target but don't actually
2N/A * manage any of the devices.
2N/A */
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == SES_ET_DEVICE ||
2N/A snp->sen_type == SES_ET_ARRAY_DEVICE)
2N/A break;
2N/A }
2N/A
2N/A if (snp == NULL)
2N/A return (0);
2N/A
2N/A props = ses_node_props(cp->sec_enclosure);
2N/A
2N/A /*
2N/A * We use the following property mappings:
2N/A *
2N/A * manufacturer vendor-id
2N/A * model product-id
2N/A * serial-number libses-chassis-serial
2N/A * part-number libses-part-number
2N/A */
2N/A verify(nvlist_lookup_string(props, SES_EN_PROP_VID,
2N/A &raw_manufacturer) == 0);
2N/A verify(nvlist_lookup_string(props, SES_EN_PROP_PID, &raw_model) == 0);
2N/A verify(nvlist_lookup_string(props, SES_EN_PROP_REV,
2N/A &raw_revision) == 0);
2N/A verify(nvlist_lookup_string(props, LIBSES_EN_PROP_CSN, &serial) == 0);
2N/A
2N/A if (*serial == '\0')
2N/A serial = "-";
2N/A
2N/A /*
2N/A * The libses-part-number comes from the decoded FRUPROM and so will
2N/A * only be available on Sun/Oracle storage arrays, so we still want to
2N/A * enumerate the ses-enclosure node, even if this property isn't
2N/A * present.
2N/A */
2N/A (void) nvlist_lookup_string(props, LIBSES_PROP_PART, &part);
2N/A
2N/A /*
2N/A * To construct the authority information, we 'clean' each string by
2N/A * removing any offensive characters and trimmming whitespace. For the
2N/A * 'product-id', we use a concatenation of 'manufacturer-model'. We
2N/A * also take the numerical serial number and convert it to a string.
2N/A */
2N/A if ((manufacturer = ses_auth_clean(mod, raw_manufacturer)) == NULL ||
2N/A (model = ses_auth_clean(mod, raw_model)) == NULL ||
2N/A (revision = ses_auth_clean(mod, raw_revision)) == NULL) {
2N/A goto error;
2N/A }
2N/A
2N/A prodlen = strlen(manufacturer) + strlen(model) + 2;
2N/A if ((product = topo_mod_alloc(mod, prodlen)) == NULL)
2N/A goto error;
2N/A
2N/A (void) snprintf(product, prodlen, "%s-%s", manufacturer, model);
2N/A
2N/A /*
2N/A * Construct the topo node and bind it to our parent.
2N/A */
2N/A if (topo_mod_nvalloc(mod, &auth, NV_UNIQUE_NAME) != 0)
2N/A goto error;
2N/A
2N/A if (nvlist_add_string(auth, FM_FMRI_AUTH_V1_CHASSIS_NM, product) != 0 ||
2N/A nvlist_add_string(auth, FM_FMRI_AUTH_V1_CHASSIS_SN, serial) != 0) {
2N/A (void) topo_mod_seterrno(mod, EMOD_NVL_INVAL);
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * We pass NULL for the parent FMRI because there is no resource
2N/A * associated with it. For the toplevel enclosure, we leave the
2N/A * serial/part/revision portions empty, which are reserved for
2N/A * individual components within the chassis.
2N/A */
2N/A if ((fmri = topo_mod_hcfmri(mod, NULL, FM_HC_SCHEME_VERSION,
2N/A SES_ENCLOSURE, cp->sec_instance, NULL, auth,
2N/A part, revision, serial)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_mod_hcfmri() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A if ((tn = topo_node_bind(mod, pnode, SES_ENCLOSURE,
2N/A cp->sec_instance, fmri)) == NULL) {
2N/A topo_mod_dprintf(mod, "topo_node_bind() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A if (topo_method_register(mod, tn, ses_enclosure_methods) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "topo_method_register() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A if (ses_set_standard_props(mod, NULL, tn, auth,
2N/A ses_node_id(cp->sec_enclosure), cp->sec_target->set_devpath) != 0)
2N/A goto error;
2N/A
2N/A if (ses_check_facility_mgmt(mod, cp, tn, props) != 0)
2N/A goto error;
2N/A
2N/A /*
2N/A * For enclosures, we want to include all possible targets (for upgrade
2N/A * purposes).
2N/A */
2N/A for (i = 0, stp = topo_list_next(&cp->sec_targets); stp != NULL;
2N/A stp = topo_list_next(stp), i++)
2N/A ;
2N/A
2N/A verify(i != 0);
2N/A paths = alloca(i * sizeof (char *));
2N/A
2N/A for (i = 0, stp = topo_list_next(&cp->sec_targets); stp != NULL;
2N/A stp = topo_list_next(stp), i++)
2N/A paths[i] = stp->set_devpath;
2N/A
2N/A
2N/A if (topo_prop_set_string_array(tn, TOPO_PGROUP_SES,
2N/A TOPO_PROP_PATHS, TOPO_PROP_IMMUTABLE, (const char **)paths,
2N/A i, &err) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to create property %s: %s\n",
2N/A TOPO_PROP_PATHS, topo_strerror(err));
2N/A goto error;
2N/A }
2N/A
2N/A if (nvlist_lookup_uint64(props,
2N/A LIBSES_PROP_PHYS_PARENT, &pindex) == 0) {
2N/A start = gethrtime(); /* to mearusre performance */
2N/A /*
2N/A * The enclosure is supported through SUNW,FRUID.
2N/A * Need to enumerate the nodes through hierarchical order.
2N/A */
2N/A if ((sproot = topo_mod_zalloc(mod,
2N/A sizeof (ses_phys_tree_t))) == NULL) {
2N/A topo_mod_dprintf(mod,
2N/A "failed to allocate root: %s\n",
2N/A topo_strerror(err));
2N/A goto error;
2N/A }
2N/A sproot->spt_pindex = pindex;
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_PROP_FRU, &sproot->spt_isfru) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_create_chassis(): Failed to find prop %s "
2N/A "on enclosure element (CSN %s).",
2N/A LIBSES_PROP_FRU, cp->sec_csn);
2N/A /* an enclosure should be a FRU. continue to process. */
2N/A sproot->spt_isfru = B_TRUE;
2N/A }
2N/A if (nvlist_lookup_uint64(props,
2N/A SES_PROP_ELEMENT_ONLY_INDEX,
2N/A &sproot->spt_eonlyindex) != 0) {
2N/A topo_mod_dprintf(mod,
2N/A "ses_create_chassis(): Failed to find prop %s "
2N/A "on enclosure element (CSN %s).",
2N/A LIBSES_PROP_PHYS_PARENT, cp->sec_csn);
2N/A topo_mod_free(mod, sproot, sizeof (ses_phys_tree_t));
2N/A goto error;
2N/A }
2N/A if (sproot->spt_pindex != sproot->spt_eonlyindex) {
2N/A topo_mod_dprintf(mod, "ses_create_chassis(): "
2N/A "Enclosure element(CSN %s) should have "
2N/A "itself as the parent to be the root node "
2N/A "of FRU hierarchical tree.)", cp->sec_csn);
2N/A topo_mod_free(mod, sproot, sizeof (ses_phys_tree_t));
2N/A goto error;
2N/A } else {
2N/A sproot->spt_snode = cp->sec_enclosure;
2N/A sproot->spt_tnode = tn;
2N/A /* construct a tree. */
2N/A if (ses_construct_phys_tree(sdp, cp, sproot) != 0) {
2N/A topo_mod_dprintf(mod, "ses_create_chassis(): "
2N/A "Failed to construct FRU hierarchical "
2N/A "tree on enclosure (CSN %s.)",
2N/A cp->sec_csn);
2N/A }
2N/A
2N/A /* enumerate elements from the tree. */
2N/A if (ses_create_children_from_phys_tree(sdp, tn, cp,
2N/A sproot) != 0) {
2N/A topo_mod_dprintf(mod, "ses_create_chassis(): "
2N/A "Failed to create children topo nodes out "
2N/A "of FRU hierarchical tree on enclosure "
2N/A "(CSN %s).", cp->sec_csn);
2N/A }
2N/A /* destroy the phys tree. */
2N/A ses_phys_tree_free(mod, sproot);
2N/A }
2N/A
2N/A end = gethrtime();
2N/A duration = end - start;
2N/A duration /= HR_SECOND;
2N/A topo_mod_dprintf(mod,
2N/A "FRU boundary tree based enumeration: %.6f seconds",
2N/A duration);
2N/A } else {
2N/A /*
2N/A * Create the nodes for power supplies, fans, controllers and
2N/A * devices. Note that SAS exopander nodes and connector nodes
2N/A * are handled through protocol specific processing of
2N/A * controllers.
2N/A */
2N/A if (ses_create_children(sdp, tn, SES_ET_POWER_SUPPLY,
2N/A PSU, "PSU", cp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_COOLING,
2N/A FAN, "FAN", cp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_ESC_ELECTRONICS,
2N/A CONTROLLER, "CONTROLLER", cp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_DEVICE,
2N/A BAY, "BAY", cp, B_TRUE) != 0 ||
2N/A ses_create_children(sdp, tn, SES_ET_ARRAY_DEVICE,
2N/A BAY, "BAY", cp, B_TRUE) != 0)
2N/A goto error;
2N/A }
2N/A
2N/A if (cp->sec_maxinstance >= 0 &&
2N/A (topo_node_range_create(mod, tn, SUBCHASSIS, 0,
2N/A cp->sec_maxinstance) != 0)) {
2N/A topo_mod_dprintf(mod, "topo_node_create_range() failed: %s",
2N/A topo_mod_errmsg(mod));
2N/A goto error;
2N/A }
2N/A
2N/A for (scp = topo_list_next(&cp->sec_subchassis); scp != NULL;
2N/A scp = topo_list_next(scp)) {
2N/A
2N/A if (ses_create_subchassis(sdp, tn, scp) != 0)
2N/A goto error;
2N/A
2N/A topo_mod_dprintf(mod, "created Subchassis node with "
2N/A "instance %u\nand target (%s) under Chassis with CSN %s",
2N/A scp->sec_instance, scp->sec_target->set_devpath,
2N/A cp->sec_csn);
2N/A
2N/A sc_count++;
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: created %llu %s nodes",
2N/A cp->sec_csn, sc_count, SUBCHASSIS);
2N/A
2N/A cp->sec_target->set_refcount++;
2N/A topo_node_setspecific(tn, cp->sec_target);
2N/A
2N/A ret = 0;
2N/Aerror:
2N/A topo_mod_strfree(mod, manufacturer);
2N/A topo_mod_strfree(mod, model);
2N/A topo_mod_strfree(mod, revision);
2N/A topo_mod_strfree(mod, product);
2N/A
2N/A nvlist_free(fmri);
2N/A nvlist_free(auth);
2N/A return (ret);
2N/A}
2N/A
2N/A/*
2N/A * Create a bay node explicitly enumerated via XML.
2N/A */
2N/Astatic int
2N/Ases_create_bays(ses_enum_data_t *sdp, tnode_t *pnode)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A ses_enum_chassis_t *cp;
2N/A
2N/A /*
2N/A * Iterate over chassis looking for an internal enclosure. This
2N/A * property is set via a vendor-specific plugin, and there should only
2N/A * ever be a single internal chassis in a system.
2N/A */
2N/A for (cp = topo_list_next(&sdp->sed_chassis); cp != NULL;
2N/A cp = topo_list_next(cp)) {
2N/A if (cp->sec_internal)
2N/A break;
2N/A }
2N/A
2N/A if (cp == NULL) {
2N/A topo_mod_dprintf(mod, "failed to find internal chassis\n");
2N/A return (-1);
2N/A }
2N/A
2N/A if (ses_create_children(sdp, pnode, SES_ET_DEVICE,
2N/A BAY, "BAY", cp, B_FALSE) != 0 ||
2N/A ses_create_children(sdp, pnode, SES_ET_ARRAY_DEVICE,
2N/A BAY, "BAY", cp, B_FALSE) != 0)
2N/A return (-1);
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Initialize chassis or subchassis.
2N/A */
2N/Astatic int
2N/Ases_init_chassis(topo_mod_t *mod, ses_enum_data_t *sdp, ses_enum_chassis_t *pcp,
2N/A ses_enum_chassis_t *cp, ses_node_t *np, nvlist_t *props,
2N/A uint64_t subchassis, ses_chassis_type_e flags)
2N/A{
2N/A boolean_t internal = B_FALSE, fru = B_FALSE;
2N/A boolean_t ext_managed = B_FALSE, reported = B_FALSE;
2N/A
2N/A assert((flags & (SES_NEW_CHASSIS | SES_NEW_SUBCHASSIS |
2N/A SES_DUP_CHASSIS | SES_DUP_SUBCHASSIS)) != 0);
2N/A
2N/A assert(cp != NULL);
2N/A assert(np != NULL);
2N/A assert(props != NULL);
2N/A
2N/A if (flags & (SES_NEW_SUBCHASSIS | SES_DUP_SUBCHASSIS))
2N/A assert(pcp != NULL);
2N/A
2N/A topo_mod_dprintf(mod, "ses_init_chassis: %s: index %llu, flags (%d)",
2N/A sdp->sed_name, subchassis, flags);
2N/A
2N/A if (flags & (SES_NEW_CHASSIS | SES_NEW_SUBCHASSIS)) {
2N/A topo_mod_dprintf(mod, "new chassis/subchassis");
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_EN_PROP_INTERNAL, &internal) == 0)
2N/A cp->sec_internal = internal;
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_PROP_FRU, &fru) == 0)
2N/A cp->sec_is_fru = fru;
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_PROP_FAULT_EXT_MANAGED, &ext_managed) == 0)
2N/A cp->sec_is_ext_managed = ext_managed;
2N/A if (nvlist_lookup_boolean_value(props,
2N/A LIBSES_EN_PROP_SENSOR_SELF_REPORTED, &reported) == 0)
2N/A cp->sec_self_report = reported;
2N/A
2N/A topo_mod_dprintf(mod, "ses_init_chassis: internal chassis(%s), "
2N/A "FRU(%s), externally managed(%s), sensor self report(%s)",
2N/A internal ? "yes" : "no", fru ? "yes" : "no",
2N/A ext_managed ? "yes" : "no", reported ? "yes" : "no");
2N/A
2N/A cp->sec_enclosure = np;
2N/A cp->sec_target = sdp->sed_target;
2N/A
2N/A if (flags & SES_NEW_CHASSIS) {
2N/A if (!cp->sec_internal)
2N/A cp->sec_instance = sdp->sed_instance++;
2N/A topo_list_append(&sdp->sed_chassis, cp);
2N/A } else {
2N/A if (subchassis != NO_SUBCHASSIS)
2N/A cp->sec_instance = subchassis;
2N/A else
2N/A cp->sec_instance = pcp->sec_scinstance++;
2N/A
2N/A if (cp->sec_instance > pcp->sec_maxinstance)
2N/A pcp->sec_maxinstance = cp->sec_instance;
2N/A
2N/A topo_list_append(&pcp->sec_subchassis, cp);
2N/A }
2N/A
2N/A } else {
2N/A topo_mod_dprintf(mod, "dup chassis/subchassis");
2N/A }
2N/A
2N/A topo_list_append(&cp->sec_targets, sdp->sed_target);
2N/A sdp->sed_current = cp;
2N/A
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Gather nodes from the current SES target into our chassis list, merging the
2N/A * results if necessary.
2N/A */
2N/Astatic ses_walk_action_t
2N/Ases_enum_gather(ses_node_t *np, void *data)
2N/A{
2N/A nvlist_t *props = ses_node_props(np);
2N/A ses_enum_data_t *sdp = data;
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A ses_enum_chassis_t *cp, *scp;
2N/A ses_enum_node_t *snp;
2N/A ses_alt_node_t *sap;
2N/A char *csn;
2N/A uint64_t instance, type;
2N/A uint64_t prevstatus, status;
2N/A uint64_t subchassis = NO_SUBCHASSIS;
2N/A
2N/A if (ses_node_type(np) == SES_NODE_ENCLOSURE) {
2N/A /*
2N/A * If we have already identified the chassis for this target,
2N/A * then this is a secondary enclosure and we should ignore it,
2N/A * along with the rest of the tree (since this is depth-first).
2N/A */
2N/A if (sdp->sed_current != NULL)
2N/A return (SES_WALK_ACTION_TERMINATE);
2N/A
2N/A /*
2N/A * Go through the list of chassis we have seen so far and see
2N/A * if this serial number matches one of the known values.
2N/A * If so, check whether this enclosure is a subchassis.
2N/A */
2N/A if (nvlist_lookup_string(props, LIBSES_EN_PROP_CSN,
2N/A &csn) != 0)
2N/A return (SES_WALK_ACTION_TERMINATE);
2N/A
2N/A (void) nvlist_lookup_uint64(props, LIBSES_EN_PROP_SUBCHASSIS_ID,
2N/A &subchassis);
2N/A
2N/A topo_mod_dprintf(mod, "ses_enum_gather: Enclosure Node (%s) "
2N/A "CSN (%s), subchassis (%llu)", sdp->sed_name, csn,
2N/A subchassis);
2N/A
2N/A /*
2N/A * We need to determine whether this enclosure node
2N/A * represents a chassis or a subchassis. Since we may
2N/A * receive the enclosure nodes in a non-deterministic
2N/A * manner, we need to account for all possible combinations:
2N/A * 1. Chassis for the current CSN has not yet been
2N/A * allocated
2N/A * 1.1 This is a new chassis:
2N/A * allocate and instantiate the chassis
2N/A * 1.2 This is a new subchassis:
2N/A * allocate a placeholder chassis
2N/A * allocate and instantiate the subchassis
2N/A * link the subchassis to the chassis
2N/A * 2. Chassis for the current CSN has been allocated
2N/A * 2.1 This is a duplicate chassis enclosure
2N/A * check whether to override old chassis
2N/A * append to chassis' target list
2N/A * 2.2 Only placeholder chassis exists
2N/A * fill in the chassis fields
2N/A * 2.3 This is a new subchassis
2N/A * allocate and instantiate the subchassis
2N/A * link the subchassis to the chassis
2N/A * 2.4 This is a duplicate subchassis enclosure
2N/A * check whether to override old chassis
2N/A * append to chassis' target list
2N/A */
2N/A
2N/A for (cp = topo_list_next(&sdp->sed_chassis); cp != NULL;
2N/A cp = topo_list_next(cp))
2N/A if (strcmp(cp->sec_csn, csn) == 0)
2N/A break;
2N/A
2N/A if (cp == NULL) {
2N/A /* 1. Haven't seen a chassis with this CSN before */
2N/A
2N/A if ((cp = topo_mod_zalloc(mod,
2N/A sizeof (ses_enum_chassis_t))) == NULL)
2N/A goto error;
2N/A
2N/A cp->sec_scinstance = SES_STARTING_SUBCHASSIS;
2N/A cp->sec_maxinstance = -1;
2N/A cp->sec_csn = csn;
2N/A
2N/A if (subchassis == NO_SUBCHASSIS) {
2N/A /* 1.1 This is a new chassis */
2N/A
2N/A topo_mod_dprintf(mod, "%s: Initialize new "
2N/A "chassis with CSN %s", sdp->sed_name, csn);
2N/A
2N/A if (ses_init_chassis(mod, sdp, NULL, cp,
2N/A np, props, NO_SUBCHASSIS,
2N/A SES_NEW_CHASSIS) < 0)
2N/A goto error;
2N/A } else {
2N/A /* 1.2 This is a new subchassis */
2N/A
2N/A topo_mod_dprintf(mod, "%s: Initialize new "
2N/A "subchassis with CSN %s and index %llu",
2N/A sdp->sed_name, csn, subchassis);
2N/A
2N/A if ((scp = topo_mod_zalloc(mod,
2N/A sizeof (ses_enum_chassis_t))) == NULL)
2N/A goto error;
2N/A
2N/A scp->sec_csn = csn;
2N/A
2N/A if (ses_init_chassis(mod, sdp, cp, scp, np,
2N/A props, subchassis, SES_NEW_SUBCHASSIS) < 0)
2N/A goto error;
2N/A }
2N/A } else {
2N/A /*
2N/A * We have a chassis or subchassis with this CSN. If
2N/A * it's a chassis, we must check to see whether it is
2N/A * a placeholder previously created because we found a
2N/A * subchassis with this CSN. We will know that because
2N/A * the sec_target value will not be set; it is set only
2N/A * in ses_init_chassis(). In that case, initialise it
2N/A * as a new chassis; otherwise, it's a duplicate and we
2N/A * need to append only.
2N/A */
2N/A if (subchassis == NO_SUBCHASSIS) {
2N/A if (cp->sec_target != NULL) {
2N/A /* 2.1 This is a duplicate chassis */
2N/A
2N/A topo_mod_dprintf(mod, "%s: Append "
2N/A "duplicate chassis with CSN (%s)",
2N/A sdp->sed_name, csn);
2N/A
2N/A if (ses_init_chassis(mod, sdp, NULL, cp,
2N/A np, props, NO_SUBCHASSIS,
2N/A SES_DUP_CHASSIS) < 0)
2N/A goto error;
2N/A } else {
2N/A /* Placeholder chassis - init it up */
2N/A topo_mod_dprintf(mod, "%s: Initialize"
2N/A "placeholder chassis with CSN %s",
2N/A sdp->sed_name, csn);
2N/A
2N/A if (ses_init_chassis(mod, sdp, NULL,
2N/A cp, np, props, NO_SUBCHASSIS,
2N/A SES_NEW_CHASSIS) < 0)
2N/A goto error;
2N/A
2N/A }
2N/A } else {
2N/A /* This is a subchassis */
2N/A
2N/A for (scp = topo_list_next(&cp->sec_subchassis);
2N/A scp != NULL; scp = topo_list_next(scp))
2N/A if (scp->sec_instance == subchassis)
2N/A break;
2N/A
2N/A if (scp == NULL) {
2N/A /* 2.3 This is a new subchassis */
2N/A
2N/A topo_mod_dprintf(mod, "%s: Initialize "
2N/A "new subchassis with CSN (%s) "
2N/A "and LID (%s)",
2N/A sdp->sed_name, csn);
2N/A
2N/A if ((scp = topo_mod_zalloc(mod,
2N/A sizeof (ses_enum_chassis_t)))
2N/A == NULL)
2N/A goto error;
2N/A
2N/A scp->sec_csn = csn;
2N/A
2N/A if (ses_init_chassis(mod, sdp, cp, scp,
2N/A np, props, subchassis,
2N/A SES_NEW_SUBCHASSIS) < 0)
2N/A goto error;
2N/A } else {
2N/A /* 2.4 This is a duplicate subchassis */
2N/A
2N/A topo_mod_dprintf(mod, "%s: Append "
2N/A "duplicate subchassis with "
2N/A "CSN (%s)", sdp->sed_name, csn);
2N/A
2N/A if (ses_init_chassis(mod, sdp, cp, scp,
2N/A np, props, subchassis,
2N/A SES_DUP_SUBCHASSIS) < 0)
2N/A goto error;
2N/A }
2N/A }
2N/A }
2N/A } else if (ses_node_type(np) == SES_NODE_ELEMENT) {
2N/A /*
2N/A * If we haven't yet seen an enclosure node and identified the
2N/A * current chassis, something is very wrong; bail out.
2N/A */
2N/A if (sdp->sed_current == NULL)
2N/A return (SES_WALK_ACTION_TERMINATE);
2N/A
2N/A /*
2N/A * If this isn't one of the element types we care about, then
2N/A * ignore it.
2N/A */
2N/A verify(nvlist_lookup_uint64(props, SES_PROP_ELEMENT_TYPE,
2N/A &type) == 0);
2N/A if (type != SES_ET_DEVICE &&
2N/A type != SES_ET_ARRAY_DEVICE &&
2N/A type != SES_ET_SUNW_FANBOARD &&
2N/A type != SES_ET_SUNW_FANMODULE &&
2N/A type != SES_ET_COOLING &&
2N/A type != SES_ET_SUNW_POWERBOARD &&
2N/A type != SES_ET_SUNW_POWERMODULE &&
2N/A type != SES_ET_POWER_SUPPLY &&
2N/A type != SES_ET_ESC_ELECTRONICS &&
2N/A type != SES_ET_SAS_EXPANDER &&
2N/A type != SES_ET_SAS_CONNECTOR)
2N/A return (SES_WALK_ACTION_CONTINUE);
2N/A
2N/A /*
2N/A * Get the current instance number and see if we already know
2N/A * about this element. If so, it means we have multiple paths
2N/A * to the same elements, and we should ignore the current path.
2N/A */
2N/A verify(nvlist_lookup_uint64(props, SES_PROP_ELEMENT_CLASS_INDEX,
2N/A &instance) == 0);
2N/A if (type == SES_ET_DEVICE || type == SES_ET_ARRAY_DEVICE)
2N/A (void) nvlist_lookup_uint64(props, SES_PROP_BAY_NUMBER,
2N/A &instance);
2N/A
2N/A cp = sdp->sed_current;
2N/A
2N/A for (snp = topo_list_next(&cp->sec_nodes); snp != NULL;
2N/A snp = topo_list_next(snp)) {
2N/A if (snp->sen_type == type &&
2N/A snp->sen_instance == instance)
2N/A break;
2N/A }
2N/A
2N/A /*
2N/A * We prefer the new element under the following circumstances:
2N/A *
2N/A * - The currently known element's status is unknown or not
2N/A * available, but the new element has a known status. This
2N/A * occurs if a given element is only available through a
2N/A * particular target.
2N/A */
2N/A if (snp != NULL) {
2N/A if (nvlist_lookup_uint64(
2N/A ses_node_props(snp->sen_node),
2N/A SES_PROP_STATUS_CODE, &prevstatus) != 0)
2N/A prevstatus = SES_ESC_UNSUPPORTED;
2N/A if (nvlist_lookup_uint64(
2N/A props, SES_PROP_STATUS_CODE, &status) != 0)
2N/A status = SES_ESC_UNSUPPORTED;
2N/A
2N/A topo_mod_dprintf(mod, "ses_enum_gather: chassis(%s) "
2N/A "target(%s) node(type %llu, instance %llu) "
2N/A "status(current: %llu previous: %llu)",
2N/A sdp->sed_current->sec_csn, sdp->sed_name,
2N/A type, instance, status, prevstatus);
2N/A
2N/A if (SES_STATUS_UNAVAIL(
2N/A sdp->sed_current->sec_is_ext_managed, prevstatus) &&
2N/A !SES_STATUS_UNAVAIL(
2N/A sdp->sed_current->sec_is_ext_managed, status)) {
2N/A topo_mod_dprintf(mod, "ses_enum_gather: "
2N/A "replacing the current topo node");
2N/A snp->sen_node = np;
2N/A snp->sen_target = sdp->sed_target;
2N/A }
2N/A
2N/A if ((sap = topo_mod_zalloc(mod,
2N/A sizeof (ses_alt_node_t))) == NULL)
2N/A goto error;
2N/A
2N/A sap->san_node = np;
2N/A sap->san_target = sdp->sed_target;
2N/A topo_list_append(&snp->sen_alt_nodes, sap);
2N/A
2N/A return (SES_WALK_ACTION_CONTINUE);
2N/A }
2N/A
2N/A if ((snp = topo_mod_zalloc(mod,
2N/A sizeof (ses_enum_node_t))) == NULL)
2N/A goto error;
2N/A
2N/A if ((sap = topo_mod_zalloc(mod,
2N/A sizeof (ses_alt_node_t))) == NULL) {
2N/A topo_mod_free(mod, snp, sizeof (ses_enum_node_t));
2N/A goto error;
2N/A }
2N/A
2N/A topo_mod_dprintf(mod, "%s: adding node (%llu, %llu)",
2N/A sdp->sed_name, type, instance);
2N/A snp->sen_node = np;
2N/A snp->sen_type = type;
2N/A snp->sen_instance = instance;
2N/A snp->sen_target = sdp->sed_target;
2N/A sap->san_node = np;
2N/A sap->san_target = sdp->sed_target;
2N/A topo_list_append(&snp->sen_alt_nodes, sap);
2N/A topo_list_append(&cp->sec_nodes, snp);
2N/A
2N/A if (type == SES_ET_DEVICE)
2N/A cp->sec_hasdev = B_TRUE;
2N/A }
2N/A
2N/A return (SES_WALK_ACTION_CONTINUE);
2N/A
2N/Aerror:
2N/A sdp->sed_errno = -1;
2N/A return (SES_WALK_ACTION_TERMINATE);
2N/A}
2N/A
2N/Astatic int
2N/Ases_process_dir(const char *dirpath, ses_enum_data_t *sdp)
2N/A{
2N/A topo_mod_t *mod = sdp->sed_mod;
2N/A DIR *dir;
2N/A struct dirent *dp;
2N/A char path[PATH_MAX];
2N/A ses_enum_target_t *stp;
2N/A int err = -1;
2N/A
2N/A /*
2N/A * Open the SES target directory and iterate over any available
2N/A * targets.
2N/A */
2N/A if ((dir = opendir(dirpath)) == NULL) {
2N/A /*
2N/A * If the SES target directory does not exist, then return as if
2N/A * there are no active targets.
2N/A */
2N/A topo_mod_dprintf(mod, "failed to open ses "
2N/A "directory '%s'", dirpath);
2N/A return (0);
2N/A }
2N/A
2N/A while ((dp = readdir(dir)) != NULL) {
2N/A if (strcmp(dp->d_name, ".") == 0 ||
2N/A strcmp(dp->d_name, "..") == 0)
2N/A continue;
2N/A
2N/A /*
2N/A * Create a new target instance and take a snapshot.
2N/A */
2N/A if ((stp = topo_mod_zalloc(mod,
2N/A sizeof (ses_enum_target_t))) == NULL)
2N/A goto error;
2N/A
2N/A (void) pthread_mutex_init(&stp->set_lock, NULL);
2N/A
2N/A (void) snprintf(path, sizeof (path), "%s/%s", dirpath,
2N/A dp->d_name);
2N/A
2N/A /*
2N/A * We keep track of the SES device path and export it on a
2N/A * per-node basis to allow higher level software to get to the
2N/A * corresponding SES state.
2N/A */
2N/A if ((stp->set_devpath = topo_mod_strdup(mod, path)) == NULL) {
2N/A topo_mod_free(mod, stp, sizeof (ses_enum_target_t));
2N/A goto error;
2N/A }
2N/A
2N/A if ((stp->set_target =
2N/A ses_open(LIBSES_VERSION, path)) == NULL) {
2N/A topo_mod_dprintf(mod, "failed to open ses target "
2N/A "'%s': %s", dp->d_name, ses_errmsg());
2N/A
2N/A ses_sof_alloc(stp->set_devpath);
2N/A topo_mod_strfree(mod, stp->set_devpath);
2N/A topo_mod_free(mod, stp, sizeof (ses_enum_target_t));
2N/A continue;
2N/A }
2N/A topo_mod_dprintf(mod, "open contract");
2N/A ses_ssl_alloc(mod, stp);
2N/A ses_create_contract(mod, stp);
2N/A
2N/A stp->set_refcount = 1;
2N/A sdp->sed_target = stp;
2N/A stp->set_snap = ses_snap_hold(stp->set_target);
2N/A stp->set_snaptime = gethrtime();
2N/A
2N/A /*
2N/A * Enumerate over all SES elements and merge them into the
2N/A * correct ses_enum_chassis_t.
2N/A */
2N/A sdp->sed_current = NULL;
2N/A sdp->sed_errno = 0;
2N/A sdp->sed_name = dp->d_name;
2N/A (void) ses_walk(stp->set_snap, ses_enum_gather, sdp);
2N/A
2N/A if (sdp->sed_errno != 0)
2N/A goto error;
2N/A }
2N/A
2N/A err = 0;
2N/Aerror:
2N/A (void) closedir(dir);
2N/A return (err);
2N/A}
2N/A
2N/Astatic void
2N/Ases_release(topo_mod_t *mod, tnode_t *tn)
2N/A{
2N/A ses_enum_target_t *stp;
2N/A
2N/A if ((stp = topo_node_getspecific(tn)) != NULL) {
2N/A topo_node_setspecific(tn, NULL);
2N/A ses_target_free(mod, stp);
2N/A }
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Ases_enum(topo_mod_t *mod, tnode_t *rnode, const char *name,
2N/A topo_instance_t min, topo_instance_t max, void *arg, void *reqdata)
2N/A{
2N/A ses_enum_chassis_t *cp;
2N/A ses_enum_data_t *data;
2N/A
2N/A /*
2N/A * Check to make sure we're being invoked sensibly, and that we're not
2N/A * being invoked as part of a post-processing step.
2N/A */
2N/A if (strcmp(name, SES_ENCLOSURE) != 0 && strcmp(name, BAY) != 0)
2N/A return (0);
2N/A
2N/A /*
2N/A * If this is the first time we've called our enumeration method, then
2N/A * gather information about any available enclosures.
2N/A */
2N/A if ((data = topo_mod_getspecific(mod)) == NULL) {
2N/A ses_sof_freeall(1);
2N/A if ((data = topo_mod_zalloc(mod, sizeof (ses_enum_data_t))) ==
2N/A NULL)
2N/A return (-1);
2N/A
2N/A data->sed_mod = mod;
2N/A topo_mod_setspecific(mod, data);
2N/A
2N/A if (ses_dev_list_gather(mod, &data->sed_devs) != 0)
2N/A goto error;
2N/A
2N/A /*
2N/A * We search both the ses(7D) and sgen(7D) locations, so we are
2N/A * independent of any particular driver class bindings.
2N/A */
2N/A if (ses_process_dir("/dev/es", data) != 0 ||
2N/A ses_process_dir("/dev/scsi/ses", data) != 0)
2N/A goto error;
2N/A }
2N/A
2N/A if (strcmp(name, SES_ENCLOSURE) == 0) {
2N/A /*
2N/A * This is a request to enumerate enclosures. Go
2N/A * through all the targets and create chassis nodes where
2N/A * necessary for an external enclosure. For an internal
2N/A * enclosure no chassis is created since the platform chassis
2N/A * itself is considered to be the chassis for internal SES
2N/A * elements.
2N/A */
2N/A for (cp = topo_list_next(&data->sed_chassis); cp != NULL;
2N/A cp = topo_list_next(cp)) {
2N/A if (strcmp(topo_node_name(rnode), CHASSIS) == 0) {
2N/A /*
2N/A * reqdata can be passed to get max instance
2N/A * number used for expander attached internal
2N/A * bays.
2N/A * It is a kludge but can avoid overhead
2N/A * to parse topo just to get the max instance
2N/A * of previously enumerated bays for
2N/A * coordinating instance nubmer for any other
2N/A * bays under chassis.
2N/A */
2N/A if (cp->sec_internal) {
2N/A if (ses_genenum_internal_drive(data,
2N/A rnode, cp,
2N/A reqdata ? reqdata : NULL) != 0)
2N/A goto error;
2N/A }
2N/A } else {
2N/A if (ses_create_chassis(data, rnode, cp) != 0)
2N/A goto error;
2N/A }
2N/A }
2N/A } else {
2N/A /*
2N/A * This is a request to enumerate a specific bay underneath the
2N/A * root chassis (for internal disks).
2N/A */
2N/A if (ses_create_bays(data, rnode) != 0)
2N/A goto error;
2N/A }
2N/A
2N/A /*
2N/A * This is a bit of a kludge. In order to allow internal disks to be
2N/A * enumerated and share snapshot-specific information with the external
2N/A * enclosure enumeration, we rely on the fact that we will be invoked
2N/A * for the 'ses-enclosure' node last.
2N/A */
2N/A if (strcmp(name, SES_ENCLOSURE) == 0) {
2N/A for (cp = topo_list_next(&data->sed_chassis); cp != NULL;
2N/A cp = topo_list_next(cp))
2N/A ses_data_free(data, cp);
2N/A ses_data_free(data, NULL);
2N/A topo_mod_setspecific(mod, NULL);
2N/A }
2N/A return (0);
2N/A
2N/Aerror:
2N/A for (cp = topo_list_next(&data->sed_chassis); cp != NULL;
2N/A cp = topo_list_next(cp))
2N/A ses_data_free(data, cp);
2N/A ses_data_free(data, NULL);
2N/A topo_mod_setspecific(mod, NULL);
2N/A return (-1);
2N/A}
2N/A
2N/Astatic const topo_modops_t ses_ops =
2N/A { ses_enum, ses_release };
2N/A
2N/Astatic topo_modinfo_t ses_info =
2N/A { SES_ENCLOSURE, FM_FMRI_SCHEME_HC, SES_VERSION, &ses_ops };
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/A_topo_init(topo_mod_t *mod, topo_version_t version)
2N/A{
2N/A int rval;
2N/A
2N/A if (getenv("TOPOSESDEBUG") != NULL)
2N/A topo_mod_setdebug(mod);
2N/A
2N/A topo_mod_dprintf(mod, "initializing %s enumerator\n",
2N/A SES_ENCLOSURE);
2N/A
2N/A if ((rval = topo_mod_register(mod, &ses_info, TOPO_VERSION)) == 0)
2N/A ses_thread_init(mod);
2N/A
2N/A return (rval);
2N/A}
2N/A
2N/Avoid
2N/A_topo_fini(topo_mod_t *mod)
2N/A{
2N/A ses_thread_fini(mod);
2N/A ses_sof_freeall(1);
2N/A topo_mod_unregister(mod);
2N/A}