Module Name: src Committed By: mlelstv Date: Fri Dec 28 12:44:15 UTC 2018
Modified Files: src/sys/dev: ipmi.c ipmivar.h Log Message: Be more verbose about the IPMI device. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/ipmi.c cvs rdiff -u -r1.1 -r1.2 src/sys/dev/ipmivar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ipmi.c diff -u src/sys/dev/ipmi.c:1.2 src/sys/dev/ipmi.c:1.3 --- src/sys/dev/ipmi.c:1.2 Wed Dec 26 06:45:58 2018 +++ src/sys/dev/ipmi.c Fri Dec 28 12:44:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ipmi.c,v 1.2 2018/12/26 06:45:58 mlelstv Exp $ */ +/* $NetBSD: ipmi.c,v 1.3 2018/12/28 12:44:15 mlelstv Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -52,7 +52,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.2 2018/12/26 06:45:58 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.3 2018/12/28 12:44:15 mlelstv Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -163,6 +163,7 @@ static int ipmi_sendcmd(struct ipmi_soft static int ipmi_recvcmd(struct ipmi_softc *, int, int *, void *); static void ipmi_delay(struct ipmi_softc *, int); +static int ipmi_get_device_id(struct ipmi_softc *, struct ipmi_device_id *); static int ipmi_watchdog_setmode(struct sysmon_wdog *); static int ipmi_watchdog_tickle(struct sysmon_wdog *); static void ipmi_dotickle(struct ipmi_softc *); @@ -1877,8 +1878,6 @@ ipmi_match(device_t parent, cfdata_t cf, { struct ipmi_softc sc; struct ipmi_attach_args *ia = aux; - uint8_t cmd[32]; - int len; int rv = 0; memset(&sc, 0, sizeof(sc)); @@ -1891,25 +1890,10 @@ ipmi_match(device_t parent, cfdata_t cf, mutex_init(&sc.sc_cmd_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK); cv_init(&sc.sc_cmd_sleep, "ipmimtch"); - mutex_enter(&sc.sc_cmd_mtx); - /* Identify BMC device early to detect lying bios */ - if (ipmi_sendcmd(&sc, BMC_SA, 0, APP_NETFN, APP_GET_DEVICE_ID, - 0, NULL)) { - mutex_exit(&sc.sc_cmd_mtx); - dbg_printf(1, ": unable to send get device id " - "command\n"); - goto unmap; - } - if (ipmi_recvcmd(&sc, sizeof(cmd), &len, cmd)) { - mutex_exit(&sc.sc_cmd_mtx); - dbg_printf(1, ": unable to retrieve device id\n"); - goto unmap; - } - mutex_exit(&sc.sc_cmd_mtx); - dbg_dump(1, __func__, len, cmd); - rv = 1; /* GETID worked, we got IPMI */ -unmap: + if (ipmi_get_device_id(&sc, NULL) == 0) + rv = 1; + cv_destroy(&sc.sc_cmd_sleep); mutex_destroy(&sc.sc_cmd_mtx); ipmi_unmap_regs(&sc); @@ -1925,6 +1909,7 @@ ipmi_thread(void *cookie) struct ipmi_attach_args *ia = &sc->sc_ia; uint16_t rec; struct ipmi_sensor *ipmi_s; + struct ipmi_device_id id; int i; sc->sc_thread_running = true; @@ -1935,6 +1920,10 @@ ipmi_thread(void *cookie) /* Map registers */ ipmi_map_regs(sc, ia); + memset(&id, 0, sizeof(id)); + if (ipmi_get_device_id(sc, &id)) + aprint_error_dev(self, "Failed to re-query device ID\n"); + /* Scan SDRs, add sensors to list */ for (rec = 0; rec != 0xFFFF;) if (get_sdr(sc, rec, &rec)) @@ -2006,6 +1995,32 @@ ipmi_thread(void *cookie) if (ia->iaa_if_irq != -1) aprint_verbose_dev(self, " irq %d\n", ia->iaa_if_irq); + if (id.deviceid != 0) { + aprint_normal_dev(self, "ID %u.%u IPMI %x.%x%s%s\n", + id.deviceid, (id.revision & 0xf), + (id.version & 0xf), (id.version >> 4) & 0xf, + (id.fwrev1 & 0x80) ? " Initializing" : " Available", + (id.revision & 0x80) ? " +SDRs" : ""); + if (id.additional != 0) + aprint_verbose_dev(self, "Additional%s%s%s%s%s%s%s%s\n", + (id.additional & 0x80) ? " Chassis" : "", + (id.additional & 0x40) ? " Bridge" : "", + (id.additional & 0x20) ? " IPMBGen" : "", + (id.additional & 0x10) ? " IPMBRcv" : "", + (id.additional & 0x08) ? " FRU" : "", + (id.additional & 0x04) ? " SEL" : "", + (id.additional & 0x02) ? " SDR" : "", + (id.additional & 0x01) ? " Sensor" : ""); + aprint_verbose_dev(self, "Manufacturer %05x Product %04x\n", + (id.manufacturer[2] & 0xf) << 16 + | id.manufacturer[1] << 8 + | id.manufacturer[0], + id.product[1] << 8 + | id.manufacturer[0]); + aprint_verbose_dev(self, "Firmware %u.%x\n", + (id.fwrev1 & 0x7f), id.fwrev2); + } + /* setup flag to exclude iic */ ipmi_enabled = 1; @@ -2116,6 +2131,34 @@ ipmi_detach(device_t self, int flags) } static int +ipmi_get_device_id(struct ipmi_softc *sc, struct ipmi_device_id *res) +{ + uint8_t buf[32]; + int len; + int rc; + + mutex_enter(&sc->sc_cmd_mtx); + /* Identify BMC device early to detect lying bios */ + rc = ipmi_sendcmd(sc, BMC_SA, 0, APP_NETFN, APP_GET_DEVICE_ID, 0, NULL); + if (rc) { + dbg_printf(1, ": unable to send get device id " + "command\n"); + goto done; + } + rc = ipmi_recvcmd(sc, sizeof(buf), &len, buf); + if (rc) { + dbg_printf(1, ": unable to retrieve device id\n"); + } +done: + mutex_exit(&sc->sc_cmd_mtx); + + if (rc == 0 && res != NULL) + memcpy(res, buf, MIN(sizeof(*res), len)); + + return rc; +} + +static int ipmi_watchdog_setmode(struct sysmon_wdog *smwdog) { struct ipmi_softc *sc = smwdog->smw_cookie; Index: src/sys/dev/ipmivar.h diff -u src/sys/dev/ipmivar.h:1.1 src/sys/dev/ipmivar.h:1.2 --- src/sys/dev/ipmivar.h:1.1 Tue Dec 25 11:56:13 2018 +++ src/sys/dev/ipmivar.h Fri Dec 28 12:44:15 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ipmivar.h,v 1.1 2018/12/25 11:56:13 mlelstv Exp $ */ +/* $NetBSD: ipmivar.h,v 1.2 2018/12/28 12:44:15 mlelstv Exp $ */ /* * Copyright (c) 2005 Jordan Hargrave @@ -111,6 +111,18 @@ struct ipmi_softc { bool sc_buf_rsvd; }; +struct ipmi_device_id { + uint8_t deviceid; + uint8_t revision; + uint8_t fwrev1; + uint8_t fwrev2; + uint8_t version; + uint8_t additional; + uint8_t manufacturer[3]; + uint8_t product[2]; + uint8_t vendor[4]; +} __packed; + struct ipmi_thread { struct ipmi_softc *sc; volatile int running;