hc.c revision 7793aa8b1cb26c7fc1397aa9db2364098fc25543
/*
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <alloca.h>
#include <limits.h>
#include <fm/topo_mod.h>
#include <fm/fmd_fmri.h>
#include <sys/systeminfo.h>
#include <sys/systeminfo.h>
#include <topo_method.h>
#include <topo_module.h>
#include <topo_subr.h>
#include <topo_prop.h>
#include <topo_tree.h>
#include <hc.h>
topo_instance_t, void *, void *);
nvlist_t **);
nvlist_t **);
nvlist_t **);
nvlist_t **);
const char *);
const topo_method_t hc_methods[] = {
{ NULL }
};
static const topo_modops_t hc_ops =
{ hc_enum, hc_release };
static const topo_modinfo_t hc_info =
{ BANK, TOPO_STABILITY_PRIVATE },
{ BAY, TOPO_STABILITY_PRIVATE },
{ BLADE, TOPO_STABILITY_PRIVATE },
{ BRANCH, TOPO_STABILITY_PRIVATE },
{ CMP, TOPO_STABILITY_PRIVATE },
{ CHIP, TOPO_STABILITY_PRIVATE },
{ CORE, TOPO_STABILITY_PRIVATE },
{ STRAND, TOPO_STABILITY_PRIVATE },
{ CPU, TOPO_STABILITY_PRIVATE },
{ DIMM, TOPO_STABILITY_PRIVATE },
{ DISK, TOPO_STABILITY_PRIVATE },
{ DRAM, TOPO_STABILITY_PRIVATE },
{ FAN, TOPO_STABILITY_PRIVATE },
{ NIU, TOPO_STABILITY_PRIVATE },
{ NIUFN, TOPO_STABILITY_PRIVATE },
{ PSU, TOPO_STABILITY_PRIVATE },
{ RANK, TOPO_STABILITY_PRIVATE },
{ RISER, TOPO_STABILITY_PRIVATE },
{ SHELF, TOPO_STABILITY_PRIVATE },
{ XAUI, TOPO_STABILITY_PRIVATE },
};
int
{
/*
* Turn on module debugging output
*/
if (getenv("TOPOHCDEBUG"))
if (version != HC_VERSION)
return (-1); /* mod errno already set */
}
return (0);
}
void
{
}
static const topo_pgroup_info_t sys_pgroup = {
1
};
static const topo_pgroup_info_t auth_pgroup = {
1
};
static void
{
int err;
char isa[MAXNAMELEN];
return;
if (err != ETOPO_PROP_DEFD)
return;
}
/*
* Inherit if we can, it saves memory
*/
== 0)
&err);
}
&err);
}
== 0)
&err);
}
return;
isa[0] = '\0';
}
/*ARGSUSED*/
int
{
int err;
/*
* Register root node methods
*/
return (0);
}
"Request to enumerate %s component with an "
"ambiguous instance number, min (%d) != max (%d).\n",
}
return (-1);
}
return (-1);
}
/*
* Set FRU for the motherboard node
*/
return (0);
}
/*ARGSUSED*/
static void
{
}
static int
{
int err, i;
if (err != 0)
return (0);
for (i = 0; i < nhcp1; i++) {
continue;
return (0);
}
/*
* Finally, check if the FMRI's represent a facility node. If so, then
* verify that the facilty type ("sensor"|"indicator") and facility
* name match.
*/
return (1);
return (0);
return (1);
}
return (0);
}
/*ARGSUSED*/
static int
{
int ret;
if (version > TOPO_METH_COMPARE_VERSION)
if (ret < 0)
return (-1);
compare) == 0)
return (0);
else
nvlist_free(*out);
}
return (-1);
}
static ssize_t
{
int more_auth = 0;
int err, i;
return (-1);
/* Get authority, if present */
return (-1);
return (-1);
return (-1);
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
more_auth++;
more_auth++;
more_auth++;
more_auth++;
more_auth++;
}
/* hc:// */
/* authority, if any */
/* hardware-id part */
/* separating slash */
/* hc-root */
/* all the pairs */
for (i = 0; i < hcnprs; i++) {
if (i > 0)
return (0);
}
/*
* If the nvlist represents a facility node, then we append the
* facility type and name to the end of the string representation using
* the format below:
*
* ?<ftype>=<fname>
*/
FM_FMRI_FACILITY_TYPE, &ftype) != 0)
return (0);
}
return (size);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_NVL2STR_VERSION)
}
}
}
return (0);
}
static nvlist_t *
{
int err = 0;
/*
* Create base HC nvlist
*/
return (NULL);
if (err != 0) {
return (NULL);
}
/*
* Add optional payload members
*/
return (fmri);
}
static nvlist_t **
{
char *find;
int nslashes = 0;
int npairs = 0;
int i, hclen;
return (NULL);
/*
* Count equal signs and slashes to determine how many
* hc-pairs will be present in the final FMRI. There should
* be at least as many slashes as equal signs. There can be
* more, though if the string after an = includes them.
*/
return (NULL);
npairs++;
}
nslashes++;
}
/*
* Do we appear to have a well-formed string version of the FMRI?
*/
return (NULL);
}
return (NULL);
}
/*
* We go through a pretty complicated procedure to find the
* name and id for each pair. That's because, unfortunately,
* we have some ids that can have slashes within them. So
* we can't just search for the next slash after the equal sign
* and decide that starts a new pair. Instead we have to find
* an equal sign for the next pair and work our way back to the
* slash from there.
*/
for (i = 0; i < npairs; i++) {
break;
startn++;
break;
*starti = '\0';
break;
*starti++ = '=';
*endi = '\0';
break;
*endi = '=';
*endi2 = '\0';
break;
*endi2 = '/';
} else {
break;
}
break;
break;
}
if (i < npairs) {
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
return (NULL);
}
return (pa);
}
int
{
return (-1);
/*
* Make sure there are a valid authority members
*/
return (0);
}
/*
* The first colon we encounter must occur before the
* first slash
*/
goto hcabail;
do {
break;
goto hcabail;
*starti = '\0';
goto hcabail;
goto hcabail;
break;
*endi = '\0';
goto hcabail;
/*
* Return possible serial, part and revision
*/
} else {
NV_UNIQUE_NAME) == 0) {
aid);
}
} else {
}
}
return (0);
return (-1);
}
/*
* This function creates an nvlist to represent the facility portion of an
* hc-scheme node, given a string representation of the fmri. This is called by
* hc_fmri_str2nvl. If the string does not contain a facility component
* (e.g. ?<ftype>=<fname>) then it bails early and returns 0.
*
* On failure it returns -1 and sets the topo mod errno
*/
int
{
return (0);
++fac;
}
fname[0] = '\0';
++fname;
}
}
return (0);
}
/*ARGSUSED*/
static int
{
char *str;
int npairs;
int i, e;
if (version > TOPO_METH_STR2NVL_VERSION)
/* We're expecting a string version of an hc scheme FMRI */
goto hcfmbail;
goto hcfmbail;
if (e != 0) {
goto hcfmbail;
}
/*
* Clean-up
*/
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
goto hcfmbail;
goto hcfmbail;
}
return (0);
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
}
static nvlist_t *
{
int err;
return (NULL);
if (err != 0) {
return (NULL);
}
return (hc);
}
static nvlist_t *
int err)
{
int i;
for (i = 0; i < n + 1; ++i)
nvlist_free(hcl[i]);
}
return (NULL);
}
static int
{
int i;
return (1);
/*
* Only enumerate elements with correct canonical names
*/
for (i = 0; i < hc_ncanon; i++) {
break;
}
if (i >= hc_ncanon) {
name);
return (0);
} else {
return (1);
}
}
static nvlist_t *
{
int i;
if (version > FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
else if (version < FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
/*
* Check that the requested name is in our canonical list
*/
return (hc_create_seterror(mod,
/*
* Copy the parent's HC_LIST
*/
return (hc_create_seterror(mod,
}
EMOD_NOMEM));
for (i = 0; i < pelems; ++i)
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
!= 0)
return (hc_create_seterror(mod,
for (i = 0; i < pelems + 1; ++i) {
nvlist_free(hcl[i]);
}
}
return (fmri);
}
/*ARGSUSED*/
static int
{
int ret;
if (version > TOPO_METH_FMRI_VERSION)
/* First the must-have fields */
/*
* args is optional
*/
!= 0) {
} else {
/* And then optional arguments */
&pfmri);
&auth);
&part);
&serial);
}
return (-1);
return (0);
}
struct hc_walk {
void *hcw_priv;
};
/*
* Returns true if the given node is beneath the specified FMRI. This uses
* the TOPO_METH_CONTAINS method, because some enumerators (such as external
* enclosures) may want to do a comparison based on chassis WWN instead of the
* instance ID. If this comparison function fails or is not supported, then we
*/
static int
{
int err;
return (-1);
rsrc) != 0 ||
fmri) != 0) {
return (-1);
}
if (err == ETOPO_METHOD_NOTSUP) {
topo_node_name(node)) == 0 &&
} else {
return (-1);
}
} else {
&match) != 0) {
return (-1);
}
}
return (0);
}
/*
* Ideally, we should just be able to call topo_walk_bysibling(). But that
* explicitly iterate over children of the parent looking for a matching value.
*/
static int
{
int status;
else
return (status);
}
}
return (TOPO_WALK_TERMINATE);
}
/*
* Generic walker for the hc-scheme topo tree. This function uses the
* hierachical nature of the hc-scheme to efficiently step through
* the topo hc tree. Node lookups are done by topo_walk_byid() and
* topo_walk_bysibling() at each component level to avoid unnecessary
* traversal of the tree. hc_walker() never returns TOPO_WALK_NEXT, so
* whether TOPO_WALK_CHILD or TOPO_WALK_SIBLING is specified by
* topo_walk_step() doesn't affect the traversal.
*/
static int
{
int i, err;
!= 0) {
return (TOPO_WALK_ERR);
}
"complete: terminate walk\n");
return (TOPO_WALK_TERMINATE);
} else {
return (TOPO_WALK_TERMINATE);
}
}
if (err != 0) {
return (TOPO_WALK_ERR);
}
/*
* Check to see if our node matches the requested FMRI. If it doesn't
* (because the enumerator determines matching based on something other
* root), then iterate over siblings to find the matching node.
*/
return (TOPO_WALK_ERR);
if (!match)
/*
* We are at the end of the hc-list. Now, check for
* a facility leaf and walk one more time.
*/
if (err != 0) {
return (TOPO_WALK_ERR);
}
}
/*
* Otherwise, this is the node we're looking for.
*/
return (TOPO_WALK_ERR);
} else {
"complete: terminate walk\n");
return (TOPO_WALK_TERMINATE);
}
}
/*
* Move on to the next component in the hc-list
*/
if (err != 0) {
return (TOPO_WALK_ERR);
}
}
static struct hc_walk *
{
return (NULL);
}
&sz) != 0) {
"nvlist\n", FM_FMRI_HC_LIST);
return (NULL);
}
!= 0) {
"looking up %s nvlist", FM_FMRI_FACILITY);
return (NULL);
} else {
}
}
== NULL) {
return (NULL);
}
return (hwp);
}
struct prop_lookup {
const char *pl_pgroup;
const char *pl_pname;
int pl_flag;
};
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
/*
* Private args to prop method are optional
*/
!= 0) {
} else {
}
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
/*ARGSUSED*/
static int
{
int err = 0;
return (err);
}
/*ARGSUSED*/
static int
{
int err;
struct prop_lookup *plp;
if (err != 0) {
}
/*
* Private args to prop method are optional
*/
!= 0) {
else
}
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
struct hc_args {
};
static boolean_t
{
return (B_FALSE);
return (B_TRUE);
else
return (B_FALSE);
}
static int
{
int err;
/*
* check with the enumerator that created this FMRI
* (topo node)
*/
&err) < 0) {
/*
* If the method exists but failed for some other reason,
* propagate the error as making any decision over presence is
* impossible.
*/
if (err != ETOPO_METHOD_NOTSUP)
return (err);
/*
* Check the authority information. If the part id or serial
* number doesn't match, then it isn't the same FMRI.
* Otherwise, assume presence.
*/
return (err);
FM_FMRI_HC_PART)) {
}
return (EMOD_NOMEM);
TOPO_METH_PRESENT_RET, present) != 0) {
return (EMOD_NOMEM);
}
}
return (0);
}
static int
{
int err;
if (version > TOPO_METH_PRESENT_VERSION)
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
static int
{
int err;
/*
* check with the enumerator that created this FMRI
* (topo node)
*/
&err) < 0) {
/*
* enumerator didn't provide "replaced" method - so
* try "present" method
*/
&err) < 0) {
/* no present method either - assume present */
present = 1;
} else {
}
NV_UNIQUE_NAME) == 0)
FMD_OBJ_STATE_UNKNOWN) == 0)
return (0);
return (ETOPO_PROP_NVL);
}
return (0);
}
static int
{
int err;
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
static int
{
int err;
/*
* check with the enumerator that created this FMRI
* (topo node)
*/
&err) < 0) {
/*
* Err on the side of caution and return usable
*/
TOPO_METH_UNUSABLE_RET, 0) == 0)
return (0);
return (ETOPO_PROP_NVL);
}
return (err);
}
static int
{
int err;
err = -1;
else
err = 0;
} else {
err = -1;
}
return (err);
}
struct fac_lookup {
const char *fl_fac_type;
#ifdef _LP64
#else
#endif
};
static int
{
/*
* Lookup the specified facility node. Return with an error if we can't
* find it.
*/
"failed\n");
return (TOPO_WALK_ERR);
}
/*
* Invoke user's callback for each facility node in the topo list,
* passing in a pointer to the facility node
*/
(void *)flp->fl_callback_args)) != 0) {
ret = TOPO_WALK_ERR;
break;
}
}
}
return (ret);
}
static int
{
int err = 0;
struct fac_lookup *flp;
/*
* lookup arguments: hw resource, facility type, facility subtype,
* callback and callback args
*/
(char **)&flp->fl_fac_type);
#ifdef _LP64
&flp->fl_callback_args);
#else
&flp->fl_callback_args);
#endif
if (err != 0) {
"walker arg nvlist\n");
}
err = -1;
else
err = 0;
} else {
"hc walker\n");
err = -1;
}
return (err);
}