diff options
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/hc.c | 80 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/libtopo.h | 1 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/mapfile-vers | 1 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_hc.h | 8 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_mod.map | 1 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_subr.c | 84 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/common/smbios/smbios_enum.c | 157 | ||||
-rw-r--r-- | usr/src/uts/common/sys/smbios.h | 3 |
8 files changed, 251 insertions, 84 deletions
diff --git a/usr/src/lib/fm/topo/libtopo/common/hc.c b/usr/src/lib/fm/topo/libtopo/common/hc.c index b9001f0fd2..26d7b2a642 100644 --- a/usr/src/lib/fm/topo/libtopo/common/hc.c +++ b/usr/src/lib/fm/topo/libtopo/common/hc.c @@ -233,84 +233,6 @@ hc_fini(topo_mod_t *mod) topo_mod_unregister(mod); } - -static const topo_pgroup_info_t sys_pgroup = { - TOPO_PGROUP_SYSTEM, - TOPO_STABILITY_PRIVATE, - TOPO_STABILITY_PRIVATE, - 1 -}; - -static const topo_pgroup_info_t auth_pgroup = { - FM_FMRI_AUTHORITY, - TOPO_STABILITY_PRIVATE, - TOPO_STABILITY_PRIVATE, - 1 -}; - -static void -hc_prop_set(tnode_t *node, nvlist_t *auth) -{ - int err; - char isa[MAXNAMELEN]; - struct utsname uts; - char *prod, *psn, *csn, *server; - - if (auth == NULL) - return; - - if (topo_pgroup_create(node, &auth_pgroup, &err) != 0) { - if (err != ETOPO_PROP_DEFD) - return; - } - - /* - * Inherit if we can, it saves memory - */ - if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, - &err) != 0) && (err != ETOPO_PROP_DEFD)) { - if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod) - == 0) - (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, - FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod, - &err); - } - if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, - &err) != 0) && (err != ETOPO_PROP_DEFD)) { - if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &psn) - == 0) - (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, - FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, - &err); - } - if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, - &err) != 0) && (err != ETOPO_PROP_DEFD)) { - if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0) - (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, - FM_FMRI_AUTH_CHASSIS, TOPO_PROP_IMMUTABLE, csn, - &err); - } - if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, - &err) != 0) && (err != ETOPO_PROP_DEFD)) { - if (nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server) - == 0) - (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, - FM_FMRI_AUTH_SERVER, TOPO_PROP_IMMUTABLE, server, - &err); - } - - if (topo_pgroup_create(node, &sys_pgroup, &err) != 0) - return; - - isa[0] = '\0'; - (void) sysinfo(SI_ARCHITECTURE, isa, sizeof (isa)); - (void) uname(&uts); - (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_ISA, - TOPO_PROP_IMMUTABLE, isa, &err); - (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, TOPO_PROP_MACHINE, - TOPO_PROP_IMMUTABLE, uts.machine, &err); -} - /*ARGSUSED*/ int hc_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t min, @@ -364,7 +286,7 @@ hc_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t min, if (strcmp(name, MOTHERBOARD) == 0) (void) topo_node_fru_set(node, nvl, 0, &err); - hc_prop_set(node, auth); + topo_pgroup_hcset(node, auth); nvlist_free(nvl); nvlist_free(auth); diff --git a/usr/src/lib/fm/topo/libtopo/common/libtopo.h b/usr/src/lib/fm/topo/libtopo/common/libtopo.h index 3c186010ec..d9f3b69ddf 100644 --- a/usr/src/lib/fm/topo/libtopo/common/libtopo.h +++ b/usr/src/lib/fm/topo/libtopo/common/libtopo.h @@ -365,6 +365,7 @@ extern int topo_fmri_getpgrp(topo_hdl_t *, nvlist_t *, const char *, nvlist_t **, int *); extern int topo_fmri_setprop(topo_hdl_t *, nvlist_t *, const char *, nvlist_t *, int, nvlist_t *, int *); +extern void topo_pgroup_hcset(tnode_t *, nvlist_t *); /* Property node NVL names used in topo_prop_getprops */ #define TOPO_PROP_GROUP "property-group" diff --git a/usr/src/lib/fm/topo/libtopo/common/mapfile-vers b/usr/src/lib/fm/topo/libtopo/common/mapfile-vers index a894c61381..9446179dec 100644 --- a/usr/src/lib/fm/topo/libtopo/common/mapfile-vers +++ b/usr/src/lib/fm/topo/libtopo/common/mapfile-vers @@ -151,6 +151,7 @@ SYMBOL_VERSION SUNWprivate { topo_pgroup_create; topo_pgroup_destroy; topo_pgroup_info; + topo_pgroup_hcset; topo_prop_get_fmri; topo_prop_get_int32; topo_prop_get_int64; diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_hc.h b/usr/src/lib/fm/topo/libtopo/common/topo_hc.h index a136bd91b1..e68417ca42 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_hc.h +++ b/usr/src/lib/fm/topo/libtopo/common/topo_hc.h @@ -216,6 +216,14 @@ extern "C" { #define TOPO_DIMM_TYPE_LPDDR3 "LPDDR3" #define TOPO_DIMM_TYPE_LPDDR4 "LPDDR4" +#define TOPO_PGROUP_MOTHERBOARD "motherboard-properties" +#define TOPO_PROP_MB_MANUFACTURER "manufacturer" +#define TOPO_PROP_MB_PRODUCT "product-id" +#define TOPO_PROP_MB_ASSET "asset-tag" +#define TOPO_PROP_MB_FIRMWARE_VENDOR "firmware-vendor" +#define TOPO_PROP_MB_FIRMWARE_REV "firmware-revision" +#define TOPO_PROP_MB_FIRMWARE_RELDATE "firmware-release-date" + #ifdef __cplusplus } #endif diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_mod.map b/usr/src/lib/fm/topo/libtopo/common/topo_mod.map index 1c50a7cf89..c5eaab059f 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_mod.map +++ b/usr/src/lib/fm/topo/libtopo/common/topo_mod.map @@ -94,4 +94,5 @@ SYMBOL_SCOPE { topo_prop_set_fmri_array { TYPE = FUNCTION; FLAGS = extern }; topo_prop_inherit { TYPE = FUNCTION; FLAGS = extern }; topo_pgroup_create { TYPE = FUNCTION; FLAGS = extern }; + topo_pgroup_hcset { TYPE = FUNCTION; FLAGS = extern }; }; diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_subr.c b/usr/src/lib/fm/topo/libtopo/common/topo_subr.c index 7a6ed4be77..8d9408dd59 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_subr.c +++ b/usr/src/lib/fm/topo/libtopo/common/topo_subr.c @@ -22,6 +22,9 @@ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. */ +/* + * Copyright (c) 2018, Joyent, Inc. + */ #include <alloca.h> #include <ctype.h> @@ -29,6 +32,9 @@ #include <syslog.h> #include <strings.h> #include <unistd.h> +#include <sys/fm/protocol.h> +#include <sys/systeminfo.h> +#include <sys/utsname.h> #include <topo_error.h> #include <topo_subr.h> @@ -394,7 +400,7 @@ topo_led_state_name(uint8_t type, char *buf, size_t len) void topo_sensor_state_name(uint32_t sensor_type, uint8_t state, char *buf, -size_t len) + size_t len) { topo_name_trans_t *ntp; @@ -538,3 +544,79 @@ size_t len) (void) snprintf(buf, len, "0x%02x", state); } + +static const topo_pgroup_info_t sys_pgroup = { + TOPO_PGROUP_SYSTEM, + TOPO_STABILITY_PRIVATE, + TOPO_STABILITY_PRIVATE, + 1 +}; +static const topo_pgroup_info_t auth_pgroup = { + FM_FMRI_AUTHORITY, + TOPO_STABILITY_PRIVATE, + TOPO_STABILITY_PRIVATE, + 1 +}; + +void +topo_pgroup_hcset(tnode_t *node, nvlist_t *auth) +{ + int err; + char isa[MAXNAMELEN]; + struct utsname uts; + char *prod, *psn, *csn, *server; + + if (auth == NULL) + return; + + if (topo_pgroup_create(node, &auth_pgroup, &err) != 0) { + if (err != ETOPO_PROP_DEFD) + return; + } + + /* + * Inherit if we can, it saves memory + */ + if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT, + &err) != 0) && (err != ETOPO_PROP_DEFD)) { + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT, &prod) == + 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT, TOPO_PROP_IMMUTABLE, prod, + &err); + } + if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_PRODUCT_SN, + &err) != 0) && (err != ETOPO_PROP_DEFD)) { + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_PRODUCT_SN, &psn) == + 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_PRODUCT_SN, TOPO_PROP_IMMUTABLE, psn, + &err); + } + if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_CHASSIS, + &err) != 0) && (err != ETOPO_PROP_DEFD)) { + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_CHASSIS, &csn) == 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_CHASSIS, TOPO_PROP_IMMUTABLE, csn, + &err); + } + if ((topo_prop_inherit(node, FM_FMRI_AUTHORITY, FM_FMRI_AUTH_SERVER, + &err) != 0) && (err != ETOPO_PROP_DEFD)) { + if (nvlist_lookup_string(auth, FM_FMRI_AUTH_SERVER, &server) == + 0) + (void) topo_prop_set_string(node, FM_FMRI_AUTHORITY, + FM_FMRI_AUTH_SERVER, TOPO_PROP_IMMUTABLE, server, + &err); + } + + if (topo_pgroup_create(node, &sys_pgroup, &err) != 0) + return; + + if (sysinfo(SI_ARCHITECTURE, isa, sizeof (isa)) != -1) + (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, + TOPO_PROP_ISA, TOPO_PROP_IMMUTABLE, isa, &err); + + if (uname(&uts) != -1) + (void) topo_prop_set_string(node, TOPO_PGROUP_SYSTEM, + TOPO_PROP_MACHINE, TOPO_PROP_IMMUTABLE, uts.machine, &err); +} diff --git a/usr/src/lib/fm/topo/modules/common/smbios/smbios_enum.c b/usr/src/lib/fm/topo/modules/common/smbios/smbios_enum.c index 42c41697c4..4fe3c9fe02 100644 --- a/usr/src/lib/fm/topo/modules/common/smbios/smbios_enum.c +++ b/usr/src/lib/fm/topo/modules/common/smbios/smbios_enum.c @@ -90,7 +90,7 @@ static boolean_t is_valid_string(const char *str) { if (strcmp(str, SMB_DEFAULT1) != 0 && strcmp(str, SMB_DEFAULT2) != 0 && - strlen(str) > 0) + strcmp(str, SMB_DEFAULT3) != 0 && strlen(str) > 0) return (B_TRUE); return (B_FALSE); @@ -121,9 +121,9 @@ smbios_make_slot(smb_enum_data_t *smed, smbios_memdevice_t *smb_md) /* errno set */ return (NULL); } - nvlist_free(auth); if ((slotnode = topo_node_bind(mod, smed->sme_pnode, SLOT, smed->sme_slot_inst, fmri)) == NULL) { + nvlist_free(auth); nvlist_free(fmri); topo_mod_dprintf(mod, "topo_node_bind() failed: %s", topo_mod_errmsg(mod)); @@ -133,6 +133,10 @@ smbios_make_slot(smb_enum_data_t *smed, smbios_memdevice_t *smb_md) nvlist_free(fmri); fmri = NULL; + /* Create authority and system pgroups */ + topo_pgroup_hcset(slotnode, auth); + nvlist_free(auth); + if (topo_node_label_set(slotnode, (char *)smb_md->smbmd_dloc, &err) != 0) { topo_mod_dprintf(mod, "failed to set label on %s=%d: %s", @@ -226,11 +230,11 @@ smbios_make_dimm(smb_enum_data_t *smed, smbios_memdevice_t *smb_md) /* errno set */ goto err; } - nvlist_free(auth); if (topo_node_range_create(mod, slotnode, DIMM, 0, 0) < 0 || (dimmnode = topo_node_bind(mod, slotnode, DIMM, 0, fmri)) == NULL) { + nvlist_free(auth); nvlist_free(fmri); topo_mod_dprintf(mod, "failed to bind dimm node: %s", topo_mod_errmsg(mod)); @@ -238,6 +242,10 @@ smbios_make_dimm(smb_enum_data_t *smed, smbios_memdevice_t *smb_md) goto err; } + /* Create authority and system pgroups */ + topo_pgroup_hcset(dimmnode, auth); + nvlist_free(auth); + if (topo_node_fru_set(dimmnode, fmri, NULL, &err) != 0) { topo_mod_dprintf(mod, "failed to set FRU on %s: %s", DIMM, topo_strerror(err)); @@ -387,6 +395,145 @@ smbios_enum_memory(smbios_hdl_t *shp, const smbios_struct_t *sp, void *arg) return (0); } +static int +smbios_enum_motherboard(smbios_hdl_t *shp, smb_enum_data_t *smed) +{ + smbios_struct_t sp; + smbios_bboard_t smb_mb; + smbios_bios_t smb_bios; + smbios_info_t smb_info; + const char *part = NULL, *rev = NULL, *serial = NULL; + char *manuf = NULL, *prod = NULL, *asset = NULL; + char *bios_vendor = NULL, *bios_rev = NULL, *bios_reldate = NULL; + nvlist_t *auth, *fmri; + topo_mod_t *mod = smed->sme_mod; + tnode_t *mbnode; + topo_pgroup_info_t pgi; + int rc = 0, err; + + if (smbios_lookup_type(shp, SMB_TYPE_BASEBOARD, &sp) == 0 && + smbios_info_bboard(shp, sp.smbstr_id, &smb_mb) == 0 && + smbios_info_common(shp, sp.smbstr_id, &smb_info) == 0) { + if (is_valid_string(smb_info.smbi_part) == B_TRUE) + part = smb_info.smbi_part; + if (is_valid_string(smb_info.smbi_version) == B_TRUE) + rev = smb_info.smbi_version; + if (is_valid_string(smb_info.smbi_serial) == B_TRUE) + serial = smb_info.smbi_serial; + if (is_valid_string(smb_info.smbi_manufacturer) == B_TRUE) + manuf = topo_mod_clean_str(mod, + smb_info.smbi_manufacturer); + if (is_valid_string(smb_info.smbi_product) == B_TRUE) + prod = topo_mod_clean_str(mod, smb_info.smbi_product); + if (is_valid_string(smb_info.smbi_asset) == B_TRUE) + asset = topo_mod_clean_str(mod, smb_info.smbi_asset); + } + if (smbios_lookup_type(shp, SMB_TYPE_BIOS, &sp) == 0 && + smbios_info_bios(shp, &smb_bios) == 0) { + if (is_valid_string(smb_bios.smbb_vendor) == B_TRUE) + bios_vendor = topo_mod_clean_str(mod, + smb_bios.smbb_vendor); + if (is_valid_string(smb_bios.smbb_version) == B_TRUE) + bios_rev = topo_mod_clean_str(mod, + smb_bios.smbb_version); + if (is_valid_string(smb_bios.smbb_reldate) == B_TRUE) + bios_reldate = topo_mod_clean_str(mod, + smb_bios.smbb_reldate); + } + if ((auth = topo_mod_auth(mod, smed->sme_pnode)) == NULL) { + topo_mod_dprintf(mod, "topo_mod_auth() failed: %s", + topo_mod_errmsg(mod)); + /* errno set */ + goto err; + } + + if ((fmri = topo_mod_hcfmri(mod, NULL, FM_HC_SCHEME_VERSION, + MOTHERBOARD, 0, NULL, auth, part, rev, serial)) == + NULL) { + nvlist_free(auth); + topo_mod_dprintf(mod, "topo_mod_hcfmri() failed: %s", + topo_mod_errmsg(mod)); + /* errno set */ + goto err; + } + + if ((mbnode = topo_node_bind(mod, smed->sme_pnode, MOTHERBOARD, 0, + fmri)) == NULL) { + nvlist_free(auth); + nvlist_free(fmri); + topo_mod_dprintf(mod, "topo_node_bind() failed: %s", + topo_mod_errmsg(mod)); + /* errno set */ + goto err; + } + + /* Create authority and system pgroups */ + topo_pgroup_hcset(mbnode, auth); + nvlist_free(auth); + + if (topo_node_fru_set(mbnode, fmri, NULL, &err) != 0) { + topo_mod_dprintf(mod, "failed to set FRU on %s: %s", + MOTHERBOARD, topo_strerror(err)); + nvlist_free(fmri); + (void) topo_mod_seterrno(mod, err); + goto err; + } + nvlist_free(fmri); + fmri = NULL; + + if (topo_node_label_set(mbnode, "MB", &err) != 0) { + topo_mod_dprintf(mod, "failed to set label on %s: %s", + MOTHERBOARD, topo_strerror(err)); + (void) topo_mod_seterrno(mod, err); + goto err; + } + + pgi.tpi_name = TOPO_PGROUP_MOTHERBOARD; + pgi.tpi_namestab = TOPO_STABILITY_PRIVATE; + pgi.tpi_datastab = TOPO_STABILITY_PRIVATE; + pgi.tpi_version = TOPO_VERSION; + rc = topo_pgroup_create(mbnode, &pgi, &err); + + if (rc == 0 && manuf != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_MANUFACTURER, TOPO_PROP_IMMUTABLE, manuf, + &err); + if (rc == 0 && prod != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_PRODUCT, TOPO_PROP_IMMUTABLE, prod, &err); + if (rc == 0 && asset != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_ASSET, TOPO_PROP_IMMUTABLE, asset, &err); + if (rc == 0 && bios_vendor != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_FIRMWARE_VENDOR, TOPO_PROP_IMMUTABLE, + bios_vendor, &err); + if (rc == 0 && bios_rev != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_FIRMWARE_REV, TOPO_PROP_IMMUTABLE, + bios_rev, &err); + if (rc == 0 && bios_reldate != NULL) + rc += topo_prop_set_string(mbnode, TOPO_PGROUP_MOTHERBOARD, + TOPO_PROP_MB_FIRMWARE_RELDATE, TOPO_PROP_IMMUTABLE, + bios_reldate, &err); + + if (rc != 0) { + topo_mod_dprintf(mod, "error setting properties on %s node", + MOTHERBOARD); + (void) topo_mod_seterrno(mod, err); + goto err; + } +err: + topo_mod_strfree(mod, manuf); + topo_mod_strfree(mod, prod); + topo_mod_strfree(mod, asset); + topo_mod_strfree(mod, bios_vendor); + topo_mod_strfree(mod, bios_rev); + topo_mod_strfree(mod, bios_reldate); + + return (0); +} + /* * A system with a functional memory controller driver will have one mc device * node per chip instance, starting at instance 0. The driver provides an @@ -449,6 +596,10 @@ smbios_enum(topo_mod_t *mod, tnode_t *rnode, const char *name, if (smbios_iter(smbh, smbios_enum_memory, &smed) < 0) /* errno set */ return (-1); + } else if (strcmp(name, MOTHERBOARD) == 0) { + if (smbios_enum_motherboard(smbh, &smed) < 0) + /* errno set */ + return (-1); } else { topo_mod_dprintf(mod, "smbios_enum() invoked for unsupported " "node type: %s", name); diff --git a/usr/src/uts/common/sys/smbios.h b/usr/src/uts/common/sys/smbios.h index 17c8d199ec..d28141e668 100644 --- a/usr/src/uts/common/sys/smbios.h +++ b/usr/src/uts/common/sys/smbios.h @@ -21,7 +21,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. - * Copyright (c) 2017, Joyent, Inc. + * Copyright (c) 2018, Joyent, Inc. * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -178,6 +178,7 @@ typedef union { */ #define SMB_DEFAULT1 "To Be Filled By O.E.M." #define SMB_DEFAULT2 "Not Available" +#define SMB_DEFAULT3 "Default string" /* * SMBIOS Common Information. These structures do not correspond to anything |