diff options
author | Johnny Lin <johnny_lin@wiwynn.com> | 2019-10-21 09:54:36 +0800 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-10-24 15:47:40 +0000 |
commit | f4abe51b74a593962c72bbecd3ff1d95a81c82d6 (patch) | |
tree | 8c5d6dcfef0e559f9874567c7dab219e66e2e2d2 /src/drivers/ipmi/ipmi_ops.c | |
parent | 5c18db1ca81b4273b76dcef5e7e22a33efd18dd8 (diff) | |
download | coreboot-f4abe51b74a593962c72bbecd3ff1d95a81c82d6.tar.xz |
drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support
Add a function for initializing and starting FRB2 timer with the
provided countdown and action values, and a stop function for
stopping the timer.
Tested on OCP Monolake.
Change-Id: Ic91905e5f01b962473b6b3a9616266d2d95b1d6b
Signed-off-by: Johnny Lin <johnny_lin@wiwynn.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/36179
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Diffstat (limited to 'src/drivers/ipmi/ipmi_ops.c')
-rw-r--r-- | src/drivers/ipmi/ipmi_ops.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/drivers/ipmi/ipmi_ops.c b/src/drivers/ipmi/ipmi_ops.c new file mode 100644 index 0000000000..784daeb1fb --- /dev/null +++ b/src/drivers/ipmi/ipmi_ops.c @@ -0,0 +1,106 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2019 Wiwynn Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of + * the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <console/console.h> +#include "ipmi_ops.h" + +enum cb_err ipmi_init_and_start_bmc_wdt(const int port, uint16_t countdown, + uint8_t action) +{ + int ret; + struct ipmi_wdt_req req = {0}; + struct ipmi_rsp rsp; + printk(BIOS_INFO, "Initializing IPMI BMC watchdog timer\n"); + /* BIOS FRB2 */ + req.timer_use = 1; + req.timer_actions = action; + /* clear BIOS FRB2 expiration flag */ + req.timer_use_expiration_flags_clr = 2; + req.initial_countdown_val = countdown; + ret = ipmi_kcs_message(port, IPMI_NETFN_APPLICATION, 0x0, + IPMI_BMC_SET_WDG_TIMER, + (const unsigned char *) &req, sizeof(req), + (unsigned char *) &rsp, sizeof(rsp)); + + if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) { + printk(BIOS_ERR, "IPMI: %s set wdt command failed " + "(ret=%d resp=0x%x), failed to initialize and start " + "IPMI BMC watchdog timer\n", __func__, + ret, rsp.completion_code); + return CB_ERR; + } + + /* Reset command to start timer */ + ret = ipmi_kcs_message(port, IPMI_NETFN_APPLICATION, 0x0, + IPMI_BMC_RESET_WDG_TIMER, NULL, 0, + (unsigned char *) &rsp, sizeof(rsp)); + + if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) { + printk(BIOS_ERR, "IPMI: %s reset wdt command failed " + "(ret=%d resp=0x%x), failed to initialize and start " + "IPMI BMC watchdog timer\n", __func__, + ret, rsp.completion_code); + return CB_ERR; + } + + printk(BIOS_INFO, "IPMI BMC watchdog initialized and started.\n"); + return CB_SUCCESS; +} + +enum cb_err ipmi_stop_bmc_wdt(const int port) +{ + int ret; + struct ipmi_wdt_req req; + struct ipmi_wdt_rsp rsp = {0}; + struct ipmi_rsp resp; + + /* Get current timer first */ + ret = ipmi_kcs_message(port, IPMI_NETFN_APPLICATION, 0x0, + IPMI_BMC_GET_WDG_TIMER, NULL, 0, + (unsigned char *) &rsp, sizeof(rsp)); + + if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) { + printk(BIOS_ERR, "IPMI: %s get wdt command failed " + "(ret=%d resp=0x%x), IPMI BMC watchdog timer may still " + "be running\n", __func__, ret, + rsp.resp.completion_code); + return CB_ERR; + } + /* If bit 6 in timer_use is 0 then it's already stopped. */ + if (!(rsp.data.timer_use & (1 << 6))) { + printk(BIOS_DEBUG, "IPMI BMC watchdog is already stopped\n"); + return CB_SUCCESS; + } + /* Set timer stop running by clearing bit 6. */ + rsp.data.timer_use &= ~(1 << 6); + rsp.data.initial_countdown_val = 0; + req = rsp.data; + ret = ipmi_kcs_message(port, IPMI_NETFN_APPLICATION, 0x0, + IPMI_BMC_SET_WDG_TIMER, + (const unsigned char *) &req, sizeof(req), + (unsigned char *) &resp, sizeof(resp)); + + if (ret < sizeof(struct ipmi_rsp) || resp.completion_code) { + printk(BIOS_ERR, "IPMI: %s set wdt command stop timer failed " + "(ret=%d resp=0x%x), failed to stop IPMI " + "BMC watchdog timer\n", __func__, ret, + resp.completion_code); + return CB_ERR; + } + printk(BIOS_DEBUG, "IPMI BMC watchdog is stopped\n"); + + return CB_SUCCESS; +} |