Esempio n. 1
0
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);
}
Esempio n. 2
0
/*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);
}
Esempio n. 3
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);
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
/*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);
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
/*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);
}
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);
}
Esempio n. 9
0
/*
 * 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);
}
Esempio n. 10
0
/*
 * 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);
}
Esempio n. 11
0
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);
}
Esempio n. 12
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);
}
Esempio n. 13
0
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);
}
Esempio n. 14
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);
}
Esempio n. 15
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);
}
Esempio n. 16
0
/* create the disk topo node */
static int
disk_tnode_create(topo_mod_t *mod, tnode_t *parent,
    dev_di_node_t *dnode, const char *name, topo_instance_t i, tnode_t **rval)
{
	int		len;
	nvlist_t	*fmri;
	tnode_t		*dtn;
	char		*part = NULL;
	nvlist_t	*auth;
	char		*mfg, *model, *firm, *serial;

	*rval = NULL;
	if (dnode != NULL) {
		mfg = topo_mod_clean_str(mod, dnode->ddn_mfg);
		model = topo_mod_clean_str(mod, dnode->ddn_model);
		firm = topo_mod_clean_str(mod, dnode->ddn_firm);
		serial = topo_mod_clean_str(mod, dnode->ddn_serial);
	} else {
		mfg = model = firm = serial = NULL;
	}

	/* form 'part=' of fmri as "<mfg>-<model>" */
	if (mfg != NULL && model != NULL) {
		len = strlen(mfg) + 1 + strlen(model) + 1;
		if ((part = topo_mod_alloc(mod, len)) != NULL)
			(void) snprintf(part, len, "%s-%s",
			    mfg, model);
	}

	auth = topo_mod_auth(mod, parent);
	fmri = topo_mod_hcfmri(mod, parent, FM_HC_SCHEME_VERSION, name, i, NULL,
	    auth, part ? part : model, firm, serial);
	nvlist_free(auth);

	topo_mod_strfree(mod, part);
	topo_mod_strfree(mod, mfg);
	topo_mod_strfree(mod, model);
	topo_mod_strfree(mod, firm);
	topo_mod_strfree(mod, serial);

	if (fmri == NULL) {
		topo_mod_dprintf(mod, "disk_tnode_create: "
		    "hcfmri (%s%d/%s%d) error %s\n",
		    topo_node_name(parent), topo_node_instance(parent),
		    name, i, topo_strerror(topo_mod_errno(mod)));
		return (-1);
	}

	if ((dtn = topo_node_bind(mod, parent, name, i, fmri)) == NULL) {
		if (topo_mod_errno(mod) == EMOD_NODE_BOUND) {
			/*
			 * if disk 0 is already there then we're done
			 */
			nvlist_free(fmri);
			return (0);
		}
		topo_mod_dprintf(mod, "disk_tnode_create: "
		    "bind (%s%d/%s%d) error %s\n",
		    topo_node_name(parent), topo_node_instance(parent),
		    name, i, topo_strerror(topo_mod_errno(mod)));
		nvlist_free(fmri);
		return (-1);
	}
	nvlist_free(fmri);

	/* add the properties of the disk */
	if (disk_set_props(mod, parent, dtn, dnode) != 0) {
		topo_mod_dprintf(mod, "disk_tnode_create: "
		    "disk_set_props (%s%d/%s%d) error %s\n",
		    topo_node_name(parent), topo_node_instance(parent),
		    name, i, topo_strerror(topo_mod_errno(mod)));
		topo_node_unbind(dtn);
		return (-1);
	}

	if (dnode->ddn_devid != NULL &&
	    disk_add_temp_sensor(mod, dtn, dnode->ddn_devid) != 0) {
		topo_mod_dprintf(mod, "disk_tnode_create: failed to create "
		    "temperature sensor node on bay=%d/disk=0",
		    topo_node_instance(parent));
	}
	*rval = dtn;
	return (0);
}
Esempio n. 17
0
/*
 * opl_hb_enum gets the ioboard instance passed in, and determines the
 * hostbridge and root complex instances numbers based on the bus addresses.
 */
int
opl_hb_enum(topo_mod_t *mp, const ioboard_contents_t *iob, tnode_t *ion,
    int brd)
{
	int hb;
	int rc;
	di_node_t p;
	tnode_t *hbnode;
	tnode_t *rcnode;
	topo_mod_t *pcimod;

	/* Load the pcibus module. We'll need it later. */
	pcimod = topo_mod_load(mp, PCI_BUS, PCI_BUS_VERS);
	if (pcimod == NULL) {
		topo_mod_dprintf(mp, "can't load pcibus module: %s\n",
		    topo_strerror(topo_mod_errno(mp)));
		return (-1);
	}

	/* For each hostbridge on an ioboard... */
	for (hb = 0; hb < OPL_HB_MAX; hb++) {
		hbnode = NULL;
		/* For each root complex in a hostbridge... */
		for (rc = 0; rc < OPL_RC_MAX; rc++) {
			p = iob->rcs[hb][rc];
			/* If no root complex, continue */
			if (p == DI_NODE_NIL) {
				continue;
			}

			/* The root complex exists! */
			topo_mod_dprintf(mp, "declaring "
			    "/chassis=0/ioboard=%d/hostbridge=%d/pciexrc=%d\n",
			    brd, hb, rc);

			/*
			 * If we haven't created a hostbridge node yet, do it
			 * now.
			 */
			if (hbnode == NULL) {
				hbnode = opl_hb_node_create(mp, ion, hb);
				if (hbnode == NULL) {
					topo_mod_dprintf(mp,
					    "unable to create hbnode: %s\n",
					    topo_strerror(topo_mod_errno(mp)));
					topo_mod_unload(pcimod);
					return (-1);
				}

			}

			/* Create the root complex node */
			rcnode = opl_rc_node_create(mp, hbnode, p, rc);
			if (rcnode == NULL) {
				topo_mod_dprintf(mp,
				    "unable to create rcnode: %s\n",
				    topo_strerror(topo_mod_errno(mp)));
				topo_mod_unload(pcimod);
				return (-1);
			}

			/* Enumerate pcibus nodes under the root complex */
			if (topo_mod_enumerate(pcimod, rcnode,
			    PCI_BUS, PCIEX_BUS, 0, 255, NULL) != 0) {
				topo_mod_dprintf(mp,
				    "error enumerating pcibus: %s\n",
				    topo_strerror(topo_mod_errno(mp)));
				topo_mod_unload(pcimod);
				return (-1);
			}
		}
	}
	topo_mod_unload(pcimod);
	return (0);
}
Esempio n. 18
0
static tnode_t *
mb_tnode_create(topo_mod_t *mod, tnode_t *parent,
    const char *name, topo_instance_t i, void *priv)
{
	nvlist_t *fmri;
	tnode_t *ntn;
	char *serial = NULL, *part = NULL;
	char *psn = NULL, *csn = NULL, *pstr = NULL;
	nvlist_t *auth = topo_mod_auth(mod, parent);

	/*
	 * Get Product Serial Number, Chassis ID, MB Serial Number and
	 * Part Number from PRI.
	 */
	(void) mb_get_pri_info(mod, &serial, &part, &csn, &psn);

	if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &pstr) != 0 &&
	    csn != NULL) {
		if (nvlist_add_string(auth, FM_FMRI_AUTH_CHASSIS, csn) != 0) {
			topo_mod_dprintf(mod,
			    "failed to add chassis to auth");
			nvlist_free(auth);
			return (NULL);
		}
	}

	if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &pstr) != 0 &&
	    psn != NULL) {
		if (nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, psn)
		    != 0) {
			topo_mod_dprintf(mod,
			    "failed to add product-sn to auth");
			nvlist_free(auth);
			return (NULL);
		}
	}

	fmri = topo_mod_hcfmri(mod, NULL, FM_HC_SCHEME_VERSION, name, i,
	    NULL, auth, part, NULL, serial);

	topo_mod_strfree(mod, serial);
	topo_mod_strfree(mod, part);
	topo_mod_strfree(mod, csn);
	topo_mod_strfree(mod, psn);

	if (fmri == NULL) {
		topo_mod_dprintf(mod,
		    "Unable to make nvlist for %s bind: %s.\n",
		    name, topo_mod_errmsg(mod));
		nvlist_free(auth);
		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(auth);
		nvlist_free(fmri);
		return (NULL);
	}

	mb_prop_set(ntn, auth);

	nvlist_free(auth);
	nvlist_free(fmri);

	topo_node_setspecific(ntn, priv);

	return (ntn);
}
Esempio n. 19
0
/*
 * Enumerate hostbridge on the cpuboard.  Hostbridge and root complex instances
 * match the cpuboard instance.
 */
int
cpuboard_hb_enum(topo_mod_t *mp, di_node_t dnode, char *rcpath,
    tnode_t *cpubn, int brd)
{
	int hb;
	int rc;
	tnode_t *hbnode;
	tnode_t *rcnode;
	topo_mod_t *pcimod;

	topo_mod_dprintf(mp, "cpuboard_hb_enum: brd: %d, cpubn=%p\n",
	    brd, cpubn);

	/* Load the pcibus module. We'll need it later. */
	pcimod = topo_mod_load(mp, PCI_BUS, PCI_BUS_VERS);
	if (pcimod == NULL) {
		topo_mod_dprintf(mp, "can't load pcibus module: %s\n",
		    topo_strerror(topo_mod_errno(mp)));
		return (-1);
	}
	hb = rc = brd;

	/* The root complex exists! */
	topo_mod_dprintf(mp, "declaring "
	    "/motherboard=0/cpuboard=%d/hostbridge=%d/"
	    "pciexrc=%d\n", brd, hb, rc);

	/* Create the hostbridge node */
	hbnode = cpuboard_hb_node_create(mp, cpubn, hb);
	if (hbnode == NULL) {
		topo_mod_dprintf(mp,
		    "unable to create hbnode: %s\n",
		    topo_strerror(topo_mod_errno(mp)));
		topo_mod_unload(pcimod);
		return (-1);
	}
	/* Create the root complex node */
	rcnode = cpuboard_rc_node_create(mp, hbnode, dnode, rcpath, rc);
	if (rcnode == NULL) {
		topo_mod_dprintf(mp,
		    "unable to create rcnode: %s\n",
		    topo_strerror(topo_mod_errno(mp)));
		topo_mod_unload(pcimod);
		return (-1);
	}
	/*
	 * If dnode not NULL, enumerate pcibus nodes under the root complex.
	 * If dnode NULL, skip enumeration.  Condition could occur if the RC
	 * is assigned to non-control domain.
	 */
	if ((dnode != NULL) && topo_mod_enumerate(pcimod, rcnode,
	    PCI_BUS, PCIEX_BUS, 0, 255, NULL) != 0) {
		topo_mod_dprintf(mp,
		    "error enumerating pcibus: %s\n",
		    topo_strerror(topo_mod_errno(mp)));
		topo_mod_unload(pcimod);
		return (-1);
	}
	topo_mod_unload(pcimod);
	return (0);
}