diff options
author | Rob Johnston <rob.johnston@joyent.com> | 2017-12-22 09:00:22 +0000 |
---|---|---|
committer | Rob Johnston <rob.johnston@joyent.com> | 2018-02-02 01:42:34 +0000 |
commit | ffa9defc1d3296f24ed42b3d7f6c331d241aae4a (patch) | |
tree | 095de595bf1ebfd7d6d081e9fee81bd45bbad0b2 | |
parent | 4a99ae161887bed6eed6dcb1699f188f023921a2 (diff) | |
download | illumos-joyent-ffa9defc1d3296f24ed42b3d7f6c331d241aae4a.tar.gz |
OS-6536 Expose vendor-name/device-name/subsystem-name as props on pciexfn topo nodes
Reviewed by: Robert Mustacchi <rm@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/Makefile.com | 3 | ||||
-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 | 3 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_mod.c | 14 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_mod.h | 2 | ||||
-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_snap.c | 3 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/libtopo/common/topo_tree.h | 4 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_props.c | 91 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/common/pcibus/did_props.h | 21 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/i86pc/hostbridge/Makefile | 3 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/i86pc/pcibus/Makefile | 4 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/i86pc/x86pi/Makefile | 4 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/sun4/hostbridge/Makefile.hb | 3 | ||||
-rw-r--r-- | usr/src/lib/fm/topo/modules/sun4/pcibus/Makefile.pci | 3 |
15 files changed, 142 insertions, 18 deletions
diff --git a/usr/src/lib/fm/topo/libtopo/Makefile.com b/usr/src/lib/fm/topo/libtopo/Makefile.com index 56871dd6d4..21ae880d59 100644 --- a/usr/src/lib/fm/topo/libtopo/Makefile.com +++ b/usr/src/lib/fm/topo/libtopo/Makefile.com @@ -20,6 +20,7 @@ # # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, Joyent, Inc. # LIBRARY = libtopo.a @@ -87,7 +88,7 @@ LINTFLAGS64 = -msux -m64 $(DYNLIB) := LDLIBS += \ -lnvpair -lelf -lumem -lxml2 -lkstat -luuid -ldevinfo \ - -lsmbios -lc -ldevid -lipmi -lscf + -lsmbios -lc -ldevid -lipmi -lscf -lpcidb $(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC) $(LINTLIB) := LINTFLAGS = -nsvx diff --git a/usr/src/lib/fm/topo/libtopo/common/mapfile-vers b/usr/src/lib/fm/topo/libtopo/common/mapfile-vers index 26bba754a1..34aebfff5f 100644 --- a/usr/src/lib/fm/topo/libtopo/common/mapfile-vers +++ b/usr/src/lib/fm/topo/libtopo/common/mapfile-vers @@ -112,6 +112,7 @@ SYMBOL_VERSION SUNWprivate { topo_mod_nvalloc; topo_mod_nvdup; topo_mod_nvl2str; + topo_mod_pcidb; topo_mod_pkgfmri; topo_mod_prominfo; topo_mod_register; 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 e0efd3f79d..8a4df466a9 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_hc.h +++ b/usr/src/lib/fm/topo/libtopo/common/topo_hc.h @@ -111,7 +111,10 @@ extern "C" { #define TOPO_PGROUP_PCI "pci" #define TOPO_PCI_VENDID "vendor-id" +#define TOPO_PCI_VENDNM "vendor-name" +#define TOPO_PCI_SUBSYSNM "subsystem-name" #define TOPO_PCI_DEVID "device-id" +#define TOPO_PCI_DEVNM "device-name" #define TOPO_PCI_EXCAP "extended-capabilities" #define TOPO_PCI_BDF "BDF" #define TOPO_PCI_CLASS "class-code" diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_mod.c b/usr/src/lib/fm/topo/libtopo/common/topo_mod.c index 0fef1f7ca0..72d40475f8 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_mod.c +++ b/usr/src/lib/fm/topo/libtopo/common/topo_mod.c @@ -91,6 +91,7 @@ #include <unistd.h> #include <stdio.h> #include <ctype.h> +#include <pcidb.h> #include <sys/param.h> #include <sys/utsname.h> #include <sys/smbios.h> @@ -457,7 +458,7 @@ topo_mod_cpufmri(topo_mod_t *mod, int version, uint32_t cpu_id, uint8_t cpumask, nvlist_t * topo_mod_memfmri(topo_mod_t *mod, int version, uint64_t pa, uint64_t offset, - const char *unum, int flags) + const char *unum, int flags) { int err; nvlist_t *args = NULL, *fmri = NULL; @@ -733,6 +734,17 @@ topo_mod_prominfo(topo_mod_t *mod) return (topo_hdl_prominfo(mod->tm_hdl)); } +pcidb_hdl_t * +topo_mod_pcidb(topo_mod_t *mod) +{ + topo_hdl_t *thp = mod->tm_hdl; + + if (thp->th_pcidb == NULL) + thp->th_pcidb = pcidb_open(PCIDB_VERSION); + + return (thp->th_pcidb); +} + void topo_mod_clrdebug(topo_mod_t *mod) { diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_mod.h b/usr/src/lib/fm/topo/libtopo/common/topo_mod.h index 517a593caf..9986fbd89f 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_mod.h +++ b/usr/src/lib/fm/topo/libtopo/common/topo_mod.h @@ -35,6 +35,7 @@ #include <libnvpair.h> #include <libdevinfo.h> #include <smbios.h> +#include <pcidb.h> #ifdef __cplusplus extern "C" { @@ -127,6 +128,7 @@ extern di_node_t topo_mod_devinfo(topo_mod_t *); extern ipmi_handle_t *topo_mod_ipmi_hold(topo_mod_t *); extern void topo_mod_ipmi_rele(topo_mod_t *); extern smbios_hdl_t *topo_mod_smbios(topo_mod_t *); +extern pcidb_hdl_t *topo_mod_pcidb(topo_mod_t *); extern di_prom_handle_t topo_mod_prominfo(topo_mod_t *); extern nvlist_t *topo_mod_auth(topo_mod_t *, tnode_t *); 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 1e5920c27b..1c50a7cf89 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_mod.map +++ b/usr/src/lib/fm/topo/libtopo/common/topo_mod.map @@ -70,6 +70,7 @@ SYMBOL_SCOPE { topo_mod_walk_init { TYPE = FUNCTION; FLAGS = extern }; topo_mod_smbios { TYPE = FUNCTION; FLAGS = extern }; + topo_mod_pcidb { TYPE = FUNCTION; FLAGS = extern }; topo_method_register { TYPE = FUNCTION; FLAGS = extern }; topo_method_unregister { TYPE = FUNCTION; FLAGS = extern }; diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_snap.c b/usr/src/lib/fm/topo/libtopo/common/topo_snap.c index 53d91cd838..fe2efb60f6 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_snap.c +++ b/usr/src/lib/fm/topo/libtopo/common/topo_snap.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, Joyent, Inc. */ /* @@ -234,6 +235,8 @@ topo_close(topo_hdl_t *thp) ipmi_close(thp->th_ipmi); if (thp->th_smbios != NULL) smbios_close(thp->th_smbios); + if (thp->th_pcidb != NULL) + pcidb_close(thp->th_pcidb); /* * Clean-up snapshot diff --git a/usr/src/lib/fm/topo/libtopo/common/topo_tree.h b/usr/src/lib/fm/topo/libtopo/common/topo_tree.h index d43b7f0f59..4c9c48cb04 100644 --- a/usr/src/lib/fm/topo/libtopo/common/topo_tree.h +++ b/usr/src/lib/fm/topo/libtopo/common/topo_tree.h @@ -23,6 +23,9 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright (c) 2018, Joyent, Inc. + */ #ifndef _TOPO_TREE_H #define _TOPO_TREE_H @@ -122,6 +125,7 @@ struct topo_hdl { ipmi_handle_t *th_ipmi; /* IPMI handle */ pthread_mutex_t th_ipmi_lock; /* IPMI lock */ smbios_hdl_t *th_smbios; /* SMBIOS handle */ + pcidb_hdl_t *th_pcidb; /* libpcidb handle */ }; #define TOPO_UUID_SIZE 37 /* libuuid limit + 1 */ diff --git a/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c index 2fcc36e924..6d900c2989 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.c @@ -23,6 +23,9 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright (c) 2018, Joyent, Inc. + */ #include <assert.h> #include <alloca.h> @@ -41,6 +44,7 @@ #include <did.h> #include <did_props.h> #include <fm/libtopo.h> +#include <pcidb.h> static int ASRU_set(tnode_t *, did_t *, const char *, const char *, const char *); @@ -66,6 +70,8 @@ static int maybe_di_uint_to_dec_str(tnode_t *, did_t *, const char *, const char *, const char *); static int AADDR_set(tnode_t *, did_t *, const char *, const char *, const char *); +static int maybe_pcidb_set(tnode_t *, did_t *, + const char *, const char *, const char *); /* * Arrays of "property translation routines" to set the properties a @@ -146,7 +152,15 @@ txprop_t Fn_common_props[] = { { DI_AADDRPROP, &pci_pgroup, TOPO_PCI_AADDR, AADDR_set }, { NULL, &protocol_pgroup, TOPO_PROP_LABEL, label_set }, { NULL, &protocol_pgroup, TOPO_PROP_FRU, FRU_set }, - { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set } + { NULL, &protocol_pgroup, TOPO_PROP_ASRU, ASRU_set }, + /* + * This entry will attempt to set the following three properties via + * lookups in the PCI database: + * - vendor-name + * - device-name + * - subsystem-name + */ + { NULL, &pci_pgroup, NULL, maybe_pcidb_set } }; txprop_t Dev_common_props[] = { @@ -911,6 +925,81 @@ BDF_set(tnode_t *tn, did_t *pd, const char *dpnm, const char *tpgrp, return (0); } +/*ARGSUSED*/ +static int +maybe_pcidb_set(tnode_t *tn, did_t *pd, const char *dpnm, const char *tpgrp, + const char *tpnm) +{ + const char *vname, *dname = NULL, *ssname = NULL; + uint_t vid, pid, svid, ssid; + pcidb_vendor_t *pciv; + pcidb_device_t *pcid; + pcidb_subvd_t *pcis = NULL; + pcidb_hdl_t *pcih; + topo_mod_t *mod = did_mod(pd); + int err; + + /* + * At a minimum, we need the vid/devid of the device to be able to + * lookup anything in the PCI database. So if we fail to look either + * of those up, bail out. + */ + if (di_uintprop_get(did_mod(pd), did_dinode(pd), DI_VENDIDPROP, &vid) < + 0 || di_uintprop_get(did_mod(pd), did_dinode(pd), DI_DEVIDPROP, + &pid) < 0) { + return (0); + } + /* + * If we fail to lookup the vendor, by the vid that's also a + * deal-breaker. + */ + if ((pcih = topo_mod_pcidb(mod)) == NULL || + (pciv = pcidb_lookup_vendor(pcih, vid)) == NULL) { + return (0); + } + + /* lookup vendor-name and set the topo property, if found */ + vname = pcidb_vendor_name(pciv); + if (vname != NULL && + topo_prop_set_string(tn, tpgrp, TOPO_PCI_VENDNM, + TOPO_PROP_IMMUTABLE, vname, &err) != 0) { + return (topo_mod_seterrno(mod, err)); + } + + /* lookup device-name and set the topo property, if found */ + if ((pcid = pcidb_lookup_device_by_vendor(pciv, pid)) != NULL) { + dname = pcidb_device_name(pcid); + } + if (dname != NULL && + topo_prop_set_string(tn, tpgrp, TOPO_PCI_DEVNM, + TOPO_PROP_IMMUTABLE, dname, &err) != 0) { + return (topo_mod_seterrno(mod, err)); + } + + /* + * Not all devices will have a subsystem-name that we can lookup, + * but if both subsystem-vendorid and subsystem-id exist in devinfo and + * if we were previously able to find the device by devid then we can + * at least attempt a lookup. If found, set the topo property. + */ + if (pcid != NULL && + di_uintprop_get(did_mod(pd), did_dinode(pd), DI_SUBVENDIDPROP, + &svid) == 0 && + di_uintprop_get(did_mod(pd), did_dinode(pd), DI_SUBSYSTEMID, + &ssid) == 0) { + pcis = pcidb_lookup_subvd_by_device(pcid, svid, ssid); + } + if (pcis != NULL) { + ssname = pcidb_subvd_name(pcis); + } + if (ssname != NULL && strlen(ssname) > 0 && + topo_prop_set_string(tn, tpgrp, TOPO_PCI_SUBSYSNM, + TOPO_PROP_IMMUTABLE, ssname, &err) != 0) { + return (topo_mod_seterrno(mod, err)); + } + return (0); +} + int did_props_set(tnode_t *tn, did_t *pd, txprop_t txarray[], int txnum) { diff --git a/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h index 5f01b18b69..cddf90e79d 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h +++ b/usr/src/lib/fm/topo/modules/common/pcibus/did_props.h @@ -21,6 +21,7 @@ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, Joyent, Inc. */ #ifndef _DID_PROPS_H @@ -58,15 +59,17 @@ typedef struct txprop { const char *, const char *, const char *); } txprop_t; -#define DI_DEVTYPPROP "device_type" -#define DI_VENDIDPROP "vendor-id" -#define DI_DEVIDPROP "device-id" -#define DI_CLASSPROP "class-code" -#define DI_REGPROP "reg" -#define DI_CCPROP "class-code" -#define DI_PHYSPROP "physical-slot#" -#define DI_SLOTPROP "slot-names" -#define DI_AADDRPROP "assigned-addresses" +#define DI_DEVTYPPROP "device_type" +#define DI_VENDIDPROP "vendor-id" +#define DI_SUBVENDIDPROP "subsystem-vendor-id" +#define DI_SUBSYSTEMID "subsystem-id" +#define DI_DEVIDPROP "device-id" +#define DI_CLASSPROP "class-code" +#define DI_REGPROP "reg" +#define DI_CCPROP "class-code" +#define DI_PHYSPROP "physical-slot#" +#define DI_SLOTPROP "slot-names" +#define DI_AADDRPROP "assigned-addresses" #define DI_RECEPTACLE_PHYMASK "receptacle-pm" #define DI_RECEPTACLE_LABEL "receptacle-label" diff --git a/usr/src/lib/fm/topo/modules/i86pc/hostbridge/Makefile b/usr/src/lib/fm/topo/modules/i86pc/hostbridge/Makefile index 2642fa859a..bc9e4471fb 100644 --- a/usr/src/lib/fm/topo/modules/i86pc/hostbridge/Makefile +++ b/usr/src/lib/fm/topo/modules/i86pc/hostbridge/Makefile @@ -20,6 +20,7 @@ # # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, Joyent, Inc. # MODULE = hostbridge @@ -33,7 +34,7 @@ MODULESRCS = $(HBSRCS) $(UTILSRCS) include ../../Makefile.plugin -LDLIBS += -ldevinfo -lsmbios +LDLIBS += -ldevinfo -lsmbios -lpcidb CPPFLAGS += -I$(UTILDIR) -I$(HBDIR) diff --git a/usr/src/lib/fm/topo/modules/i86pc/pcibus/Makefile b/usr/src/lib/fm/topo/modules/i86pc/pcibus/Makefile index b41606985a..1a5c04ec39 100644 --- a/usr/src/lib/fm/topo/modules/i86pc/pcibus/Makefile +++ b/usr/src/lib/fm/topo/modules/i86pc/pcibus/Makefile @@ -21,7 +21,7 @@ # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright (c) 2017, Joyent, Inc. +# Copyright (c) 2018, Joyent, Inc. # MODULE = pcibus @@ -37,6 +37,6 @@ MODULESRCS = $(UTILSRCS) $(PCISRCS) pci_i86pc.c include ../../Makefile.plugin -LDLIBS += -ldevinfo -lsmbios +LDLIBS += -ldevinfo -lsmbios -lpcidb CPPFLAGS += -I$(UTILDIR) -I$(HBDIR) -I $(NICDIR) diff --git a/usr/src/lib/fm/topo/modules/i86pc/x86pi/Makefile b/usr/src/lib/fm/topo/modules/i86pc/x86pi/Makefile index acaf762aa3..4ac5dc7e1c 100644 --- a/usr/src/lib/fm/topo/modules/i86pc/x86pi/Makefile +++ b/usr/src/lib/fm/topo/modules/i86pc/x86pi/Makefile @@ -23,6 +23,8 @@ # Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright (c) 2018, Joyent, Inc. +# MODULE = x86pi ARCH = i86pc @@ -39,7 +41,7 @@ MODULESRCS = $(X86PISRCS) $(UTILSRCS) include ../../Makefile.plugin -LDLIBS += -lsmbios -ldevinfo -luutil +LDLIBS += -lsmbios -ldevinfo -luutil -lpcidb CPPFLAGS += -I. -I$(ROOT)/usr/platform/i86pc/include -I$(TOPODIR) CPPFLAGS += -I$(UTILDIR) -I$(BRDIR) diff --git a/usr/src/lib/fm/topo/modules/sun4/hostbridge/Makefile.hb b/usr/src/lib/fm/topo/modules/sun4/hostbridge/Makefile.hb index 7d610c9b9c..342b44cb6d 100644 --- a/usr/src/lib/fm/topo/modules/sun4/hostbridge/Makefile.hb +++ b/usr/src/lib/fm/topo/modules/sun4/hostbridge/Makefile.hb @@ -21,6 +21,7 @@ # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, Joyent, Inc. # MODULE = hostbridge @@ -33,7 +34,7 @@ MODULESRCS = $(HBSRCS) $($(ARCH)_SRCS) include ../../Makefile.plugin -LDLIBS += -ldevinfo -lsmbios +LDLIBS += -ldevinfo -lsmbios -lpcidb CPPFLAGS += -I$(SUN4DIR) -I$(UTILDIR) -I$(HBDIR) %.o: $(SUN4DIR)/%.c diff --git a/usr/src/lib/fm/topo/modules/sun4/pcibus/Makefile.pci b/usr/src/lib/fm/topo/modules/sun4/pcibus/Makefile.pci index 82ecb535c2..620a2c388d 100644 --- a/usr/src/lib/fm/topo/modules/sun4/pcibus/Makefile.pci +++ b/usr/src/lib/fm/topo/modules/sun4/pcibus/Makefile.pci @@ -21,6 +21,7 @@ # # Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, Joyent, Inc. # MODULE = pcibus @@ -36,7 +37,7 @@ MODULESRCS = $(PCISRCS) $(UTILSRCS) pci_$(ARCH).c include ../../Makefile.plugin -LDLIBS += -ldevinfo -lsmbios +LDLIBS += -ldevinfo -lsmbios -lpcidb CPPFLAGS += -I$(SUN4DIR) -I$(UTILDIR) -I$(HBDIR) -I$(NICDIR) %.o: $(SUN4DIR)/%.c |