static int disk_declare(topo_mod_t *mod, tnode_t *parent, dev_di_node_t *dnode, tnode_t **childp) { tnode_t *dtn = NULL; int rval; rval = disk_tnode_create(mod, parent, dnode, DISK, 0, &dtn); if (dtn == NULL) { if (rval == 0) return (0); topo_mod_dprintf(mod, "disk_declare: " "disk_tnode_create error %s\n", topo_strerror(topo_mod_errno(mod))); return (-1); } /* register disk_methods against the disk topo node */ if (topo_method_register(mod, dtn, disk_methods) != 0) { topo_mod_dprintf(mod, "disk_declare: " "topo_method_register error %s\n", topo_strerror(topo_mod_errno(mod))); topo_node_unbind(dtn); return (-1); } if (childp != NULL) *childp = dtn; return (0); }
/* * Walk all of the topology nodes looking for DISKs that match the structure * described in the overview. Once we find them, check their fault status * and update their fault indiciator accordingly. */ static void dl_examine_topo(disk_lights_t *dl) { int err; topo_hdl_t *thp = NULL; topo_walk_t *twp = NULL; thp = fmd_hdl_topo_hold(dl->dl_fmd, TOPO_VERSION); if ((twp = topo_walk_init(thp, FM_FMRI_SCHEME_HC, dl_fault_walk_outer, dl, &err)) == NULL) { fmd_hdl_error(dl->dl_fmd, "failed to get topology: %s\n", topo_strerror(err)); goto out; } if (topo_walk_step(twp, TOPO_WALK_CHILD) == TOPO_WALK_ERR) { fmd_hdl_error(dl->dl_fmd, "failed to walk topology: %s\n", topo_strerror(err)); goto out; } out: if (twp != NULL) topo_walk_fini(twp); if (thp != NULL) fmd_hdl_topo_rele(dl->dl_fmd, thp); }
static void print_props(topo_hdl_t *thp, tnode_t *node) { int i, err; nvlist_t *nvl; struct prop_args *pp; if (pcnt == 0) return; for (i = 0; i < pcnt; ++i) { pp = pargs[i]; if (pp->group == NULL) continue; /* * If we have a valid value, this is a request to * set a property. Otherwise, just print the property * group and any specified properties. */ if (pp->value == NULL) { if (pp->prop == NULL) { /* * Print all properties in this group */ if ((nvl = topo_prop_getprops(node, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to " "get %s: %s\n", g_pname, pp->group, topo_strerror(err)); continue; } else { print_all_props(thp, node, nvl, pp->group); nvlist_free(nvl); continue; } } if (topo_prop_getprop(node, pp->group, pp->prop, NULL, &nvl, &err) < 0) { (void) fprintf(stderr, "%s: failed to get " "%s.%s: %s\n", g_pname, pp->group, pp->prop, topo_strerror(err)); continue; } else { print_pgroup(thp, node, pp->group, NULL, NULL, 0); print_prop_nameval(thp, node, nvl); nvlist_free(nvl); } } else { set_prop(thp, node, NULL, pp); } } }
/*ARGSUSED*/ static int niu_enum(topo_mod_t *mod, tnode_t *rnode, const char *name, topo_instance_t min, topo_instance_t max, void *arg, void *notused) { tnode_t *niun; di_node_t devtree; di_node_t dnode; if (strcmp(name, NIU) != 0) { topo_mod_dprintf(mod, "Currently only know how to enumerate %s components.\n", NIU); return (0); } if ((devtree = topo_mod_devinfo(mod)) == DI_NODE_NIL) { topo_mod_dprintf(mod, "devinfo init failed."); return (-1); } /* * Load XAUI Enum */ if (xaui_enum_load(mod) == NULL) return (-1); dnode = di_drv_first_node("niumx", devtree); if (dnode != DI_NODE_NIL) { niun = niu_declare(rnode, name, 0, dnode, mod); if (niun == NULL) { topo_mod_dprintf(mod, "Enumeration of niu failed: %s\n", topo_strerror(topo_mod_errno(mod))); return (-1); /* mod_errno already set */ } if (topo_node_range_create(mod, niun, NIUFN, 0, NIUFN_MAX) < 0) { topo_node_unbind(niun); topo_mod_dprintf(mod, "child_range_add of NIUFN" "failed: %s\n", topo_strerror(topo_mod_errno(mod))); return (-1); /* mod_errno already set */ } if (niufn_instantiate(niun, NIUFN, dnode, mod) < 0) { topo_mod_dprintf(mod, "Enumeration of niufn " "failed %s\n", topo_strerror(topo_mod_errno(mod))); } } if (di_drv_next_node(dnode) != DI_NODE_NIL) topo_mod_dprintf(mod, "Currently only know how to enumerate one niu " "components.\n"); return (0); }
static tnode_t * iob_tnode_create(tnode_t *parent, const char *name, topo_instance_t i, void *priv, topo_mod_t *mod) { topo_hdl_t *thp; nvlist_t *args, *fmri, *pfmri; tnode_t *ntn; int err; thp = topo_mod_handle(mod); if (topo_node_resource(parent, &pfmri, &err) < 0) { topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "Unable to retrieve parent resource.\n"); return (NULL); } if (topo_mod_nvalloc(mod, &args, NV_UNIQUE_NAME) != 0) { (void) topo_mod_seterrno(mod, EMOD_FMRI_NVL); nvlist_free(pfmri); return (NULL); } err = nvlist_add_nvlist(args, TOPO_METH_FMRI_ARG_PARENT, pfmri); if (err != 0) { nvlist_free(pfmri); nvlist_free(args); (void) topo_mod_seterrno(mod, EMOD_FMRI_NVL); return (NULL); } fmri = topo_fmri_create(thp, FM_FMRI_SCHEME_HC, name, i, args, &err); if (fmri == NULL) { topo_mod_dprintf(mod, "Unable to make nvlist for %s bind.\n", name); return (NULL); } ntn = topo_node_bind(mod, parent, name, i, fmri, priv); if (ntn == NULL) { topo_mod_dprintf(mod, "topo_node_bind (%s%d/%s%d) failed: %s\n", topo_node_name(parent), topo_node_instance(parent), name, i, topo_strerror(topo_mod_errno(mod))); nvlist_free(fmri); return (NULL); } nvlist_free(fmri); if (topo_method_register(mod, ntn, Iob_methods) < 0) { topo_mod_dprintf(mod, "topo_method_register failed: %s\n", topo_strerror(topo_mod_errno(mod))); topo_node_unbind(ntn); return (NULL); } return (ntn); }
static tnode_t * hb_tnode_create(topo_mod_t *mod, tnode_t *parent, const char *name, topo_instance_t i, void *priv) { int err; nvlist_t *fmri; tnode_t *ntn; nvlist_t *auth = topo_mod_auth(mod, parent); fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL, auth, NULL, NULL, NULL); nvlist_free(auth); if (fmri == NULL) { topo_mod_dprintf(mod, "Unable to make nvlist for %s bind: %s.\n", name, topo_mod_errmsg(mod)); return (NULL); } ntn = topo_node_bind(mod, parent, name, i, fmri); if (ntn == NULL) { topo_mod_dprintf(mod, "topo_node_bind (%s%d/%s%d) failed: %s\n", topo_node_name(parent), topo_node_instance(parent), name, i, topo_strerror(topo_mod_errno(mod))); nvlist_free(fmri); return (NULL); } nvlist_free(fmri); topo_node_setspecific(ntn, priv); if (topo_pgroup_create(ntn, &hb_auth_pgroup, &err) == 0) { (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, &err); (void) topo_prop_inherit(ntn, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, &err); } if (topo_method_register(mod, ntn, Hb_methods) < 0) { topo_mod_dprintf(mod, "topo_method_register failed: %s\n", topo_strerror(topo_mod_errno(mod))); topo_node_unbind(ntn); return (NULL); } return (ntn); }
/*ARGSUSED*/ static tnode_t * niufn_declare(tnode_t *parent, const char *name, topo_instance_t i, void *priv, topo_mod_t *mod) { tnode_t *ntn; int err; if ((ntn = niu_tnode_create(mod, parent, name, i, priv)) == NULL) return (NULL); /* inherit FRU from parent */ (void) topo_node_fru_set(ntn, NULL, 0, &err); /* inherit parent's label */ (void) topo_node_label_set(ntn, NULL, &err); /* set ASRU */ (void) niu_asru_set(ntn, priv, mod); if (topo_node_range_create(mod, ntn, XAUI, 0, XAUI_MAX) < 0) { topo_node_unbind(ntn); topo_mod_dprintf(mod, "child_range_add of XAUI" "failed: %s\n", topo_strerror(topo_mod_errno(mod))); return (NULL); /* mod_errno already set */ } return (ntn); }
int did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum) { topo_mod_t *mp; int i, r, e; mp = did_mod(pd); for (i = 0; i < txnum; i++) { /* * Ensure the property group has been created. */ if (txarray[i].tx_tpgroup != NULL) { if (topo_pgroup_create(tn, txarray[i].tx_tpgroup, &e) < 0) { if (e != ETOPO_PROP_DEFD) return (topo_mod_seterrno(mp, e)); } } topo_mod_dprintf(mp, "Setting property %s in group %s.\n", txarray[i].tx_tprop, txarray[i].tx_tpgroup->tpi_name); r = txarray[i].tx_xlate(tn, pd, txarray[i].tx_diprop, txarray[i].tx_tpgroup->tpi_name, txarray[i].tx_tprop); if (r != 0) { topo_mod_dprintf(mp, "failed.\n"); topo_mod_dprintf(mp, "Error was %s.\n", topo_strerror(topo_mod_errno(mp))); return (-1); } topo_mod_dprintf(mp, "succeeded.\n"); } return (0); }
int topo_file_load(topo_hdl_t *thp, topo_mod_t *mod, ttree_t *tp) { topo_file_t *tfp; if ((tfp = topo_hdl_zalloc(thp, sizeof (topo_file_t))) == NULL) return (topo_hdl_seterrno(thp, ETOPO_NOMEM)); tp->tt_file = tfp; tfp->tf_mod = mod; if (xml_read(thp, tp) < 0) { topo_file_unload(thp, tp); return (-1); } if (topo_xml_enum(tfp->tf_mod, tfp->tf_fileinfo, tp->tt_root) < 0) { topo_dprintf(TOPO_DBG_ERR, "Failed to enumerate topology: %s\n", topo_strerror(topo_hdl_errno(thp))); topo_file_unload(thp, tp); return (-1); } return (0); }
/* * Set the label for a topo node. */ int x86pi_set_label(topo_mod_t *mod, const char *label, const char *name, tnode_t *t_node) { int result; int err; if (mod == NULL) { return (-1); } /* * Set the label for this topology node. * Note that a NULL label will inherit the label from topology * node's parent. */ result = topo_node_label_set(t_node, (char *)label, &err); if (result != 0) { (void) topo_mod_seterrno(mod, err); topo_mod_dprintf(mod, "x86pi_set_label: failed with label %s " "on %s node: %s\n", (label == NULL ? "NULL" : label), name, topo_strerror(err)); } return (result); }
/*ARGSUSED*/ static int mb_enum(topo_mod_t *mod, tnode_t *pn, const char *name, topo_instance_t min, topo_instance_t max, void *arg, void *notused) { tnode_t *mbn; if (strcmp(name, MOTHERBOARD) != 0) { topo_mod_dprintf(mod, "Currently only know how to enumerate %s components.\n", MOTHERBOARD); return (0); } mb_mod_hdl = mod; mbn = mb_declare(pn, name, 0, NULL, mod); if (mbn == NULL) { topo_mod_dprintf(mod, "Enumeration of motherboard " "failed: %s\n", topo_strerror(topo_mod_errno(mod))); return (-1); /* mod_errno already set */ } return (0); }
int pi_enum_mem(topo_mod_t *mod, md_t *mdp, mde_cookie_t mde_node, topo_instance_t inst, tnode_t *t_parent, const char *hc_name, tnode_t **t_node) { int result; int err; nvlist_t *rsrc = NULL; *t_node = NULL; /* * Create the basic topology node for the DIMM using the generic * enumerator. The dimm serial is added to the resource so * the retire agent can retire correct page whether the dimm * has been moved or not. */ result = pi_enum_generic_impl(mod, mdp, mde_node, inst, t_parent, t_parent, hc_name, _ENUM_NAME, t_node, SUN4VPI_ENUM_ADD_SERIAL); if (result != 0) { /* Error messages are printed by the generic routine */ return (result); } /* * Set ASRU compute method, using resource as argument. */ result = topo_node_resource(*t_node, &rsrc, &err); if (result != 0) { topo_mod_dprintf(mod, "%s node_0x%llx failed to get resource: %s\n", _ENUM_NAME, (uint64_t)mde_node, topo_strerror(err)); return (-1); } /* Set the ASRU on the node with COMPUTE flag */ result = topo_node_asru_set(*t_node, rsrc, TOPO_ASRU_COMPUTE, &err); nvlist_free(rsrc); if (result != 0) { topo_mod_dprintf(mod, "%s node_0x%llx failed to set ASRU: %s\n", _ENUM_NAME, (uint64_t)mde_node, topo_strerror(err)); return (-1); } return (0); }
static void print_everstyle(tnode_t *node) { char buf[PATH_MAX], numbuf[64]; nvlist_t *fmri, **hcl; int i, err; uint_t n; if (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, &fmri, &err) < 0) { (void) fprintf(stderr, "%s: failed to get fmri for %s=%d: %s\n", g_pname, topo_node_name(node), topo_node_instance(node), topo_strerror(err)); return; } if (nvlist_lookup_nvlist_array(fmri, FM_FMRI_HC_LIST, &hcl, &n) != 0) { (void) fprintf(stderr, "%s: failed to find %s for %s=%d\n", g_pname, FM_FMRI_HC_LIST, topo_node_name(node), topo_node_instance(node)); nvlist_free(fmri); return; } buf[0] = '\0'; for (i = 0; i < n; i++) { char *name, *inst, *estr; ulong_t ul; if (nvlist_lookup_string(hcl[i], FM_FMRI_HC_NAME, &name) != 0 || nvlist_lookup_string(hcl[i], FM_FMRI_HC_ID, &inst) != 0) { (void) fprintf(stderr, "%s: failed to get " "name-instance for %s=%d\n", g_pname, topo_node_name(node), topo_node_instance(node)); nvlist_free(fmri); return; } errno = 0; ul = strtoul(inst, &estr, 10); if (errno != 0 || estr == inst) { (void) fprintf(stderr, "%s: instance %s does not " "convert to an unsigned integer\n", g_pname, inst); } (void) strlcat(buf, "/", sizeof (buf)); (void) strlcat(buf, name, sizeof (buf)); (void) snprintf(numbuf, sizeof (numbuf), "%u", ul); (void) strlcat(buf, numbuf, sizeof (buf)); } nvlist_free(fmri); (void) printf("%s\n", buf); }
/*ARGSUSED*/ static nvlist_t * set_nverror(topo_hdl_t *thp, int err, int *errp, char *method, nvlist_t *nvlp) { nvlist_free(nvlp); topo_dprintf(thp, TOPO_DBG_ERR, "%s failed: %s\n", method, topo_strerror(err)); *errp = err; return (NULL); }
/*ARGSUSED*/ static int set_error(topo_hdl_t *thp, int err, int *errp, char *method, nvlist_t *nvlp) { if (nvlp != NULL) nvlist_free(nvlp); topo_dprintf(TOPO_DBG_ERR, "%s failed: %s\n", method, topo_strerror(err)); *errp = err; return (-1); }
static tnode_t * cpuboard_node_create(topo_mod_t *mp, tnode_t *parent, const char *name, int inst, void *priv) { tnode_t *node; nvlist_t *fmri; nvlist_t *auth = topo_mod_auth(mp, parent); topo_mod_dprintf(mp, "cpuboard_node_create:\n"); if (parent == NULL || inst < 0) { return (NULL); } /* Create FMRI */ if ((fmri = topo_mod_hcfmri(mp, parent, FM_HC_SCHEME_VERSION, name, inst, NULL, auth, NULL, NULL, NULL)) == NULL) { topo_mod_dprintf(mp, "create of tnode for %s failed: %s", name, topo_strerror(topo_mod_errno(mp))); nvlist_free(auth); return (NULL); } nvlist_free(auth); /* Create and bind node */ node = topo_node_bind(mp, parent, name, inst, fmri); if (node == NULL) { nvlist_free(fmri); topo_mod_dprintf(mp, "unable to bind root complex: %s\n", topo_strerror(topo_mod_errno(mp))); return (NULL); /* mod_errno already set */ } nvlist_free(fmri); topo_node_setspecific(node, priv); return (node); }
/*ARGSUSED*/ struct topo_hdl * fmd_fmri_topology(int version) { int err; if (g_thp == NULL) { if ((g_thp = topo_open(TOPO_VERSION, "/", &err)) == NULL) { (void) fprintf(stderr, "topo_open failed: %s\n", topo_strerror(err)); exit(1); } } return (g_thp); }
/* * Calculate a generic FRU for the given node. If the node is not a FRU, * then inherit the FRU data from the nodes parent. */ int x86pi_set_frufmri(topo_mod_t *mod, x86pi_hcfmri_t *hcfmri, tnode_t *t_parent, tnode_t *t_node, int flag) { int result; int err; nvlist_t *auth = NULL; nvlist_t *frufmri = NULL; if (t_node == NULL || mod == NULL) { return (-1); } /* * Determine if this node is a FRU */ if (!(flag & X86PI_ENUM_FRU)) { /* This node is not a FRU. Inherit from parent and return */ (void) topo_node_fru_set(t_node, NULL, 0, &result); return (0); } /* * This node is a FRU. Create an FMRI. */ auth = topo_mod_auth(mod, t_parent); frufmri = topo_mod_hcfmri(mod, t_parent, FM_HC_SCHEME_VERSION, hcfmri->hc_name, hcfmri->instance, NULL, auth, hcfmri->part_number, hcfmri->version, hcfmri->serial_number); if (frufmri == NULL) { topo_mod_dprintf(mod, "failed to create FRU: %s\n", topo_strerror(topo_mod_errno(mod))); } nvlist_free(auth); /* Set the FRU, whether NULL or not */ result = topo_node_fru_set(t_node, frufmri, 0, &err); if (result != 0) { (void) topo_mod_seterrno(mod, err); } nvlist_free(frufmri); return (result); }
/* * Set the FRU property to the hc fmri of this tnode */ int FRU_fmri_set(topo_mod_t *mp, tnode_t *tn) { nvlist_t *fmri; int err, e; if (topo_node_resource(tn, &fmri, &err) < 0 || fmri == NULL) { topo_mod_dprintf(mp, "FRU_fmri_set error: %s\n", topo_strerror(topo_mod_errno(mp))); return (topo_mod_seterrno(mp, err)); } e = topo_node_fru_set(tn, fmri, 0, &err); nvlist_free(fmri); if (e < 0) return (topo_mod_seterrno(mp, err)); return (0); }
static tnode_t * node_bind_seterror(topo_mod_t *mod, tnode_t *pnode, tnode_t *node, int err) { topo_node_unlock(pnode); (void) topo_mod_seterrno(mod, err); if (node == NULL) return (NULL); topo_dprintf(TOPO_DBG_ERR, "unable to bind %s=%d: " "%s\n", (node->tn_name != NULL ? node->tn_name : "unknown"), node->tn_instance, topo_strerror(err)); topo_node_lock(node); /* expected to be locked */ topo_node_destroy(node); return (NULL); }
static tnode_t * niu_tnode_create(topo_mod_t *mod, tnode_t *parent, const char *name, topo_instance_t i, void *priv) { int err; nvlist_t *fmri; tnode_t *ntn; nvlist_t *auth = topo_mod_auth(mod, parent); fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL, auth, NULL, NULL, NULL); nvlist_free(auth); if (fmri == NULL) { topo_mod_dprintf(mod, "Unable to make nvlist for %s bind: %s.\n", name, topo_mod_errmsg(mod)); return (NULL); } ntn = topo_node_bind(mod, parent, name, i, fmri); if (ntn == NULL) { topo_mod_dprintf(mod, "topo_node_bind (%s%d/%s%d) failed: %s\n", topo_node_name(parent), topo_node_instance(parent), name, i, topo_strerror(topo_mod_errno(mod))); nvlist_free(fmri); return (NULL); } nvlist_free(fmri); topo_node_setspecific(ntn, priv); if (topo_pgroup_create(ntn, &io_pgroup, &err) == 0) { (void) devprop_set(ntn, priv, TOPO_PGROUP_IO, TOPO_IO_DEV, mod); (void) driverprop_set(ntn, priv, TOPO_PGROUP_IO, TOPO_IO_DRIVER, mod); (void) moduleprop_set(ntn, priv, TOPO_PGROUP_IO, TOPO_IO_MODULE, mod); } return (ntn); }
static int walk_topo(topo_hdl_t *thp, char *uuid) { int err; topo_walk_t *twp; int flag; if ((twp = topo_walk_init(thp, opt_s, walk_node, NULL, &err)) == NULL) { (void) fprintf(stderr, "%s: failed to walk %s topology:" " %s\n", g_pname, opt_s, topo_strerror(err)); return (-1); } /* * Print standard header */ if (!opt_e) { char buf[32]; time_t tod = time(NULL); (void) printf("TIME UUID\n"); (void) strftime(buf, sizeof (buf), "%b %d %T", localtime(&tod)); (void) printf("%-15s %-32s\n", buf, uuid); (void) printf("\n"); } flag = opt_b != 0 ? TOPO_WALK_SIBLING : TOPO_WALK_CHILD; if (topo_walk_step(twp, flag) == TOPO_WALK_ERR) { (void) fprintf(stderr, "%s: failed to walk topology\n", g_pname); topo_walk_fini(twp); return (-1); } topo_walk_fini(twp); return (0); }
/*ARGSUSED*/ static tnode_t * xaui_declare(tnode_t *parent, const char *name, topo_instance_t i, void *priv, topo_mod_t *mod) { tnode_t *ntn; nvlist_t *fmri = NULL; int e; if ((ntn = xaui_tnode_create(mod, parent, name, i, NULL)) == NULL) { topo_mod_dprintf(mod, "%s ntn = NULL\n", name); return (NULL); } (void) xaui_fru_set(mod, ntn); /* when coming from pcibus: private data == parent tnode */ if (priv == (void *)parent) { ispci = 1; } (void) xaui_label_set(mod, ntn, i, priv); /* reset pcibus/niu switch */ ispci = 0; /* set ASRU to resource fmri */ if (topo_prop_get_fmri(ntn, TOPO_PGROUP_PROTOCOL, TOPO_PROP_RESOURCE, &fmri, &e) == 0) (void) topo_node_asru_set(ntn, fmri, 0, &e); nvlist_free(fmri); if (topo_node_range_create(mod, ntn, XFP, 0, XFP_MAX) < 0) { topo_node_unbind(ntn); topo_mod_dprintf(mod, "child_range_add of XFP" "failed: %s\n", topo_strerror(topo_mod_errno(mod))); return (NULL); /* mod_errno already set */ } return (ntn); }
static int node_create_seterror(topo_mod_t *mod, tnode_t *pnode, topo_nodehash_t *nhp, int err) { topo_node_unlock(pnode); topo_dprintf(TOPO_DBG_ERR, "unable to insert child:" "%s\n", topo_strerror(err)); if (nhp != NULL) { if (nhp->th_name != NULL) topo_mod_strfree(mod, nhp->th_name); if (nhp->th_nodearr != NULL) { topo_mod_free(mod, nhp->th_nodearr, nhp->th_arrlen * sizeof (tnode_t *)); } topo_mod_free(mod, nhp, sizeof (topo_nodehash_t)); } return (topo_mod_seterrno(mod, err)); }
/*ARGSUSED*/ static int fac_walker(topo_hdl_t *thp, tnode_t *node, void *arg) { int err; nvlist_t *out; if (topo_method_supported(node, TOPO_METH_FAC_ENUM, 0)) { /* * If the facility enumeration method fails, note the failure, * but continue on with the walk. */ if (topo_method_invoke(node, TOPO_METH_FAC_ENUM, 0, NULL, &out, &err) != 0) { topo_dprintf(thp, TOPO_DBG_ERR, "facility enumeration method failed on node %s=%d " "(%s)\n", topo_node_name(node), topo_node_instance(node), topo_strerror(err)); } } return (TOPO_WALK_NEXT); }
static int set_methregister_error(topo_mod_t *mod, tnode_t *node, topo_imethod_t *mp, int err) { if (mp != NULL) { topo_list_delete(&node->tn_methods, mp); if (mp->tim_name != NULL) topo_mod_strfree(mod, mp->tim_name); if (mp->tim_desc != NULL) topo_mod_strfree(mod, mp->tim_desc); topo_mod_free(mod, mp, sizeof (topo_imethod_t)); } topo_node_unlock(node); topo_dprintf(mod->tm_hdl, TOPO_DBG_ERR, "method registration failed for %s: %s\n", mod->tm_name, topo_strerror(err)); return (topo_mod_seterrno(mod, err)); }
static int niufn_instantiate(tnode_t *parent, const char *name, di_node_t pnode, topo_mod_t *mod) { di_node_t sib; tnode_t *ntn; topo_instance_t inst; if (strcmp(name, NIUFN) != 0) { topo_mod_dprintf(mod, "Currently only know how to enumerate %s components.\n", NIUFN); return (0); } sib = di_child_node(pnode); while (sib != DI_NODE_NIL) { if (niufn_instance_get(mod, sib, &inst) != 0) { topo_mod_dprintf(mod, "Enumeration of %s " "instance failed.\n", NIUFN); sib = di_sibling_node(sib); continue; } if ((ntn = niufn_declare(parent, NIUFN, inst, sib, mod)) == NULL) { topo_mod_dprintf(mod, "Enumeration of %s=%d " "failed: %s\n", NIUFN, inst, topo_strerror(topo_mod_errno(mod))); return (-1); } if (topo_mod_enumerate(mod, ntn, XAUI, XAUI, inst, inst, sib) != 0) { return (topo_mod_seterrno(mod, EMOD_PARTIAL_ENUM)); } sib = di_sibling_node(sib); } return (0); }
/* * Create a generic topo node based on the hcfmri strcuture passed in. */ int x86pi_enum_generic(topo_mod_t *mod, x86pi_hcfmri_t *hcfmri, tnode_t *t_bindparent, tnode_t *t_fmriparent, tnode_t **t_node, int flag) { int rv; int err; nvlist_t *out; nvlist_t *fmri; nvlist_t *auth; topo_mod_dprintf(mod, "%s adding entry for type (%s)\n", _ENUM_NAME, hcfmri->hc_name); if (t_bindparent == NULL) { topo_mod_dprintf(mod, "%s called with NULL parent for type %s\n", _ENUM_NAME, hcfmri->hc_name); return (-1); } /* Create the FMRI for this node */ auth = topo_mod_auth(mod, t_bindparent); fmri = topo_mod_hcfmri(mod, t_fmriparent, FM_HC_SCHEME_VERSION, hcfmri->hc_name, hcfmri->instance, NULL, auth, hcfmri->part_number, hcfmri->version, hcfmri->serial_number); nvlist_free(auth); if (fmri == NULL) { topo_mod_dprintf(mod, "%s failed to create %s fmri : %s\n", _ENUM_NAME, hcfmri->hc_name, topo_strerror(topo_mod_errno(mod))); return (-1); } rv = topo_node_range_create(mod, t_bindparent, hcfmri->hc_name, 0, 4); if (rv != 0 && topo_mod_errno(mod) != EMOD_NODE_DUP) { topo_mod_dprintf(mod, "%s range create failed for node %s\n", _ENUM_NAME, hcfmri->hc_name); } /* Bind this node to the parent */ *t_node = x86pi_node_bind(mod, t_bindparent, hcfmri, fmri, flag); nvlist_free(fmri); if (*t_node == NULL) { topo_mod_dprintf(mod, "%s failed to bind %s node instance %d: %s\n", _ENUM_NAME, hcfmri->hc_name, hcfmri->instance, topo_strerror(topo_mod_errno(mod))); return (-1); } /* call IPMI facility provider to register fac methods */ if (topo_mod_load(mod, _FAC_PROV, TOPO_VERSION) == NULL) { topo_mod_dprintf(mod, "%s: Failed to load %s module: %s\n", _ENUM_NAME, _FAC_PROV, topo_mod_errmsg(mod)); return (-1); } rv = topo_mod_enumerate(mod, *t_node, _FAC_PROV, _FAC_PROV, 0, 0, NULL); if (rv != 0) { topo_mod_dprintf(mod, "%s: %s failed: %s\n", _ENUM_NAME, _FAC_PROV, topo_mod_errmsg(mod)); return (-1); } /* invoke fac_prov_ipmi_enum method */ if (topo_method_supported(*t_node, TOPO_METH_FAC_ENUM, 0)) { if (topo_method_invoke(*t_node, TOPO_METH_FAC_ENUM, 0, NULL, &out, &err) != 0) { /* log the error and drive on */ topo_mod_dprintf(mod, "%s: TOPO_METH_FAC_ENUM failed\n", _ENUM_NAME); } else { fac_done = 1; } } topo_mod_dprintf(mod, "%s added (%s) node\n", _ENUM_NAME, topo_node_name(*t_node)); return (0); }
tnode_t * x86pi_node_bind(topo_mod_t *mod, tnode_t *t_parent, x86pi_hcfmri_t *hcfmri, nvlist_t *fmri, int flag) { int result; tnode_t *t_node; char *f = "x86pi_node_bind"; if (t_parent == NULL) { topo_mod_dprintf(mod, "%s: NULL parent for %s node instance %d\n", f, hcfmri->hc_name, hcfmri->instance); return (NULL); } /* Bind this node to the parent */ t_node = topo_node_bind(mod, t_parent, hcfmri->hc_name, hcfmri->instance, fmri); if (t_node == NULL) { topo_mod_dprintf(mod, "%s: failed to bind %s node instance %d: %s\n", f, hcfmri->hc_name, (uint32_t)hcfmri->instance, topo_strerror(topo_mod_errno(mod))); return (NULL); } topo_mod_dprintf(mod, "%s: bound %s node instance %d type %s\n", f, hcfmri->hc_name, hcfmri->instance, hcfmri->hc_name); /* * We have bound the node. Now decorate it with an appropriate * FRU and label (which may be inherited from the parent). */ result = x86pi_set_frufmri(mod, hcfmri, t_parent, t_node, flag); if (result != 0) { /* * Though we have failed to set the FRU FMRI we still continue. * The module errno is set by the called routine, so we report * the problem and move on. */ topo_mod_dprintf(mod, "%s: failed to set FRU FMRI for %s node\n", f, hcfmri->hc_name); } result = x86pi_set_label(mod, hcfmri->location, hcfmri->hc_name, t_node); if (result != 0) { /* * Though we have failed to set the label, we still continue. * The module errno is set by the called routine, so we report * the problem and move on. */ topo_mod_dprintf(mod, "%s: no label for %s node\n", f, hcfmri->hc_name); } result = x86pi_set_auth(mod, hcfmri, t_parent, t_node); if (result != 0) { /* * Though we have failed to set the authority, we still * continue. The module errno is set by the called routine, so * we report the problem and move on. */ topo_mod_dprintf(mod, "%s: no authority information for %s node\n", f, hcfmri->hc_name); } result = x86pi_set_system(mod, t_node); if (result != 0) { /* * Though we have failed to set the system group, we still * continue. The module errno is set by the called routine, so * we report the problem and move on. */ topo_mod_dprintf(mod, "%s: no system information for %s node\n", f, hcfmri->hc_name); } return (t_node); }
static int mptsas_led_mode(topo_mod_t *mod, tnode_t *node, topo_version_t vers, nvlist_t *in, nvlist_t **nvout) { int err, ret = 0; tnode_t *pnode = topo_node_parent(node); uint32_t type, ledmode = 0; nvlist_t *pargs, *nvl; char *driver = NULL, *devctl = NULL; uint32_t enclosure, slot; uint8_t mptsas_led; boolean_t set; if (vers > TOPO_METH_MPTSAS_LED_MODE_VERSION) return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW)); if (topo_prop_get_string(pnode, TOPO_PGROUP_BINDING, TOPO_BINDING_DRIVER, &driver, &err) != 0 || strcmp("mpt_sas", driver) != 0) { topo_mod_dprintf(mod, "%s: Facility driver was not mpt_sas", __func__); ret = topo_mod_seterrno(mod, EMOD_NVL_INVAL); goto out; } if (topo_prop_get_uint32(node, TOPO_PGROUP_FACILITY, TOPO_FACILITY_TYPE, &type, &err) != 0) { topo_mod_dprintf(mod, "%s: Failed to lookup %s property " "(%s)", __func__, TOPO_FACILITY_TYPE, topo_strerror(err)); return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); } switch (type) { case (TOPO_LED_TYPE_SERVICE): mptsas_led = MPTSAS_LEDCTL_LED_FAIL; break; case (TOPO_LED_TYPE_LOCATE): mptsas_led = MPTSAS_LEDCTL_LED_IDENT; break; case (TOPO_LED_TYPE_OK2RM): mptsas_led = MPTSAS_LEDCTL_LED_OK2RM; break; default: topo_mod_dprintf(mod, "%s: Invalid LED type: 0x%x\n", __func__, type); return (topo_mod_seterrno(mod, EMOD_NVL_INVAL)); } if (topo_prop_get_string(pnode, TOPO_PGROUP_BINDING, TOPO_BINDING_DEVCTL, &devctl, &err) != 0 || topo_prop_get_uint32(pnode, TOPO_PGROUP_BINDING, TOPO_BINDING_ENCLOSURE, &enclosure, &err) != 0 || topo_prop_get_uint32(pnode, TOPO_PGROUP_BINDING, TOPO_BINDING_SLOT, &slot, &err) != 0) { topo_mod_dprintf(mod, "%s: Facility was missing mpt_sas binding" " properties\n", __func__); ret = topo_mod_seterrno(mod, EMOD_NVL_INVAL); goto out; } if ((nvlist_lookup_nvlist(in, TOPO_PROP_PARGS, &pargs) == 0) && nvlist_exists(pargs, TOPO_PROP_VAL_VAL)) { /* * Set the LED mode */ set = B_TRUE; if ((ret = nvlist_lookup_uint32(pargs, TOPO_PROP_VAL_VAL, &ledmode)) != 0) { topo_mod_dprintf(mod, "%s: Failed to lookup %s nvpair " "(%s)\n", __func__, TOPO_PROP_VAL_VAL, strerror(ret)); ret = topo_mod_seterrno(mod, EMOD_NVL_INVAL); goto out; } topo_mod_dprintf(mod, "%s: Setting LED mode to %s\n", __func__, ledmode ? "ON" : "OFF"); } else { /* * Get the LED mode */ set = B_FALSE; topo_mod_dprintf(mod, "%s: Getting LED mode\n", __func__); } if (do_led_control(mod, devctl, enclosure, slot, mptsas_led, &ledmode, set) != 0) { topo_mod_dprintf(mod, "%s: do_led_control failed", __func__); ret = topo_mod_seterrno(mod, EMOD_UNKNOWN); goto out; } if (topo_mod_nvalloc(mod, &nvl, NV_UNIQUE_NAME) != 0 || nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, TOPO_LED_MODE) != 0 || nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, TOPO_TYPE_UINT32) != 0 || nvlist_add_uint32(nvl, TOPO_PROP_VAL_VAL, ledmode) != 0) { topo_mod_dprintf(mod, "%s: Failed to allocate 'out' nvlist\n", __func__); nvlist_free(nvl); ret = topo_mod_seterrno(mod, EMOD_NOMEM); goto out; } *nvout = nvl; out: if (driver != NULL) topo_mod_strfree(mod, driver); if (devctl != NULL) topo_mod_strfree(mod, devctl); return (ret); }