Johnny Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/ipmi_kcs.c M src/drivers/ipmi/ipmi_kcs.h 2 files changed, 103 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/1
diff --git a/src/drivers/ipmi/ipmi_kcs.c b/src/drivers/ipmi/ipmi_kcs.c index 4d1e3e1..d58a9c7 100644 --- a/src/drivers/ipmi/ipmi_kcs.c +++ b/src/drivers/ipmi/ipmi_kcs.c @@ -235,6 +235,85 @@ return ret; }
+int init_and_start_ipmi_bmc_wdt(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)\n", + __func__, ret, rsp.completion_code); + return 1; + } + + /* 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)\n", + __func__, ret, rsp.completion_code); + return 1; + } + + printk(BIOS_INFO, "IPMI BMC watchdog initialized and started.\n"); + return 0; +} + +int stop_ipmi_bmc_wdt(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)\n", + __func__, ret, rsp.resp.completion_code); + return 1; + } + /* 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 0; + } + /* 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)\n", + __func__, ret, resp.completion_code); + return 1; + } + printk(BIOS_DEBUG, "IPMI BMC watchdog is stopped\n"); + + return 0; +} + int ipmi_kcs_message(int port, int netfn, int lun, int cmd, const unsigned char *inmsg, int inlen, unsigned char *outmsg, int outlen) diff --git a/src/drivers/ipmi/ipmi_kcs.h b/src/drivers/ipmi/ipmi_kcs.h index a194dd2..e83d82a 100644 --- a/src/drivers/ipmi/ipmi_kcs.h +++ b/src/drivers/ipmi/ipmi_kcs.h @@ -23,6 +23,9 @@ #define IPMI_BMC_GET_DEVICE_ID 0x01 #define IPMI_IPMI_VERSION_MINOR(x) ((x) >> 4) #define IPMI_IPMI_VERSION_MAJOR(x) ((x) & 0xf) +#define IPMI_BMC_RESET_WDG_TIMER 0x22 +#define IPMI_BMC_SET_WDG_TIMER 0x24 +#define IPMI_BMC_GET_WDG_TIMER 0x25
#define IPMI_NETFN_FIRMWARE 0x08 #define IPMI_NETFN_STORAGE 0x0a @@ -33,6 +36,13 @@ extern int ipmi_kcs_message(int port, int netfn, int lun, int cmd, const unsigned char *inmsg, int inlen, unsigned char *outmsg, int outlen); +/* + * Initialize and start BMC FRB2 watchdog timer with the + * provided timer countdown and action values. + */ +int init_and_start_ipmi_bmc_wdt(int port, uint16_t countdown, + uint8_t action); +int stop_ipmi_bmc_wdt(int port);
struct ipmi_rsp { uint8_t lun; @@ -53,4 +63,18 @@ uint8_t product_id[2]; } __packed;
+/* BMC Watchdog timer */ +struct ipmi_wdt_req { + uint8_t timer_use; + uint8_t timer_actions; + uint8_t pretimeout_interval; + uint8_t timer_use_expiration_flags_clr; + uint16_t initial_countdown_val; +} __packed; + +struct ipmi_wdt_rsp { + struct ipmi_rsp resp; + struct ipmi_wdt_req data; + uint16_t present_countdown_val; +} __packed; #endif
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36179/1/src/drivers/ipmi/ipmi_kcs.c File src/drivers/ipmi/ipmi_kcs.c:
https://review.coreboot.org/c/coreboot/+/36179/1/src/drivers/ipmi/ipmi_kcs.c... PS1, Line 238: init_and_start_ipmi_bmc_wdt(int Please move those function to a separate file, as this one only handles the kcs interface. Prefix with ipmi_
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#2).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc M src/drivers/ipmi/ipmi_kcs.h A src/drivers/ipmi/ipmi_ops.c 3 files changed, 130 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/2
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#3).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc M src/drivers/ipmi/ipmi_kcs.h A src/drivers/ipmi/ipmi_ops.c 3 files changed, 130 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/3
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#4).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc M src/drivers/ipmi/ipmi_kcs.h A src/drivers/ipmi/ipmi_ops.c 3 files changed, 129 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/4
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36179/1/src/drivers/ipmi/ipmi_kcs.c File src/drivers/ipmi/ipmi_kcs.c:
https://review.coreboot.org/c/coreboot/+/36179/1/src/drivers/ipmi/ipmi_kcs.c... PS1, Line 238: init_and_start_ipmi_bmc_wdt(int
Please move those function to a separate file, as this one only handles the kcs interface. […]
Added and moved to ipmi_ops.c.
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36179/4/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/4/src/drivers/ipmi/ipmi_ops.c... PS4, Line 20: int init_and_start_ipmi_bmc_wdt(int port, uint16_t countdown, uint8_t action) Prefix with ipmi_
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#5).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc M src/drivers/ipmi/ipmi_kcs.h A src/drivers/ipmi/ipmi_ops.c 3 files changed, 129 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/5
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 5:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36179/4/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/4/src/drivers/ipmi/ipmi_ops.c... PS4, Line 20: int init_and_start_ipmi_bmc_wdt(int port, uint16_t countdown, uint8_t action)
Prefix with ipmi_
Done
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 5: Code-Review+1
(5 comments)
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h File src/drivers/ipmi/ipmi_kcs.h:
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h... PS5, Line 50: int ipmi_init_and_start_bmc_wdt(int port, uint16_t countdown, please use a separate header for those high level functions
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 19: function description, what does it return on success?
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 20: int constify arguments
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 57: function description, what does it return on success?
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 58: int ipmi_stop_bmc_wdt(int port) constify arguments
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 5:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h File src/drivers/ipmi/ipmi_kcs.h:
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h... PS5, Line 50: int ipmi_init_and_start_bmc_wdt(int port, uint16_t countdown,
please use a separate header for those high level functions
Should I only move the two function signatures to a new separate header (ipmi_ops.h) or should I also move all the added BMC WDG related codes to it? Thanks.
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#6).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc A src/drivers/ipmi/ipmi_ops.c A src/drivers/ipmi/ipmi_ops.h 3 files changed, 154 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/6
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 6:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h File src/drivers/ipmi/ipmi_kcs.h:
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_kcs.h... PS5, Line 50: int ipmi_init_and_start_bmc_wdt(int port, uint16_t countdown,
Should I only move the two function signatures to a new separate header (ipmi_ops. […]
Done
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 19:
function description, what does it return on success?
Done
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 20: int
constify arguments
Done
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 57:
function description, what does it return on success?
Done
https://review.coreboot.org/c/coreboot/+/36179/5/src/drivers/ipmi/ipmi_ops.c... PS5, Line 58: int ipmi_stop_bmc_wdt(int port)
constify arguments
Done
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 6:
(6 comments)
Nice. Could you run the new files through `clang-format` please?
https://review.coreboot.org/c/coreboot/+/36179/6//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/36179/6//COMMIT_MSG@13 PS6, Line 13: Tested on OCP Monolake. How?
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.h File src/drivers/ipmi/ipmi_ops.h:
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.h... PS6, Line 48: * Return 0 on success, return 1 on error. Please use CB_SUCCESS and friends.
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 21: uint8_t action) The line length is now longer, I believe.
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 50: printk(BIOS_ERR, "IPMI: %s reset wdt command failed (ret=%d resp=0x%x)\n", Please mention the effects of this error.
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 72: printk(BIOS_ERR, "IPMI: %s get wdt command failed (ret=%d resp=0x%x)\n", Please mention the effects in the message.
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 91: printk(BIOS_ERR, "IPMI: %s set wdt command stop timer failed (ret=%d resp=0x%x)\n", Ditto.
Hello Andrey Petrov, David Hendricks, Jingle Hsu, Sven Schnelle, Patrick Rudolph, Jonathan Zhang, build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36179
to look at the new patch set (#7).
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc A src/drivers/ipmi/ipmi_ops.c A src/drivers/ipmi/ipmi_ops.h 3 files changed, 164 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/79/36179/7
Johnny Lin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 7:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36179/6//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/36179/6//COMMIT_MSG@13 PS6, Line 13: Tested on OCP Monolake.
How?
With this change it can start FRB2 timer, if I don't stop the timer in the payload, after the specified time BMC will trigger hard reset on the system. If I stop the timer in the payload, the system will not be hard-reset after the specified time.
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.h File src/drivers/ipmi/ipmi_ops.h:
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.h... PS6, Line 48: * Return 0 on success, return 1 on error.
Please use CB_SUCCESS and friends.
Done
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c File src/drivers/ipmi/ipmi_ops.c:
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 21: uint8_t action)
The line length is now longer, I believe.
Done
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 50: printk(BIOS_ERR, "IPMI: %s reset wdt command failed (ret=%d resp=0x%x)\n",
Please mention the effects of this error.
Done
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 72: printk(BIOS_ERR, "IPMI: %s get wdt command failed (ret=%d resp=0x%x)\n",
Please mention the effects in the message.
Done
https://review.coreboot.org/c/coreboot/+/36179/6/src/drivers/ipmi/ipmi_ops.c... PS6, Line 91: printk(BIOS_ERR, "IPMI: %s set wdt command stop timer failed (ret=%d resp=0x%x)\n",
Ditto.
Done
Patrick Rudolph has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
Patch Set 7: Code-Review+2
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/36179 )
Change subject: drivers/ipmi: Add IPMI BMC FRB2 watchdog timer support ......................................................................
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 --- M src/drivers/ipmi/Makefile.inc A src/drivers/ipmi/ipmi_ops.c A src/drivers/ipmi/ipmi_ops.h 3 files changed, 164 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Rudolph: Looks good to me, approved
diff --git a/src/drivers/ipmi/Makefile.inc b/src/drivers/ipmi/Makefile.inc index a29c2e2..9d5b3d4 100644 --- a/src/drivers/ipmi/Makefile.inc +++ b/src/drivers/ipmi/Makefile.inc @@ -1,2 +1,3 @@ ramstage-$(CONFIG_IPMI_KCS) += ipmi_kcs.c ramstage-$(CONFIG_IPMI_KCS) += ipmi_kcs_ops.c +ramstage-$(CONFIG_IPMI_KCS) += ipmi_ops.c diff --git a/src/drivers/ipmi/ipmi_ops.c b/src/drivers/ipmi/ipmi_ops.c new file mode 100644 index 0000000..784daeb --- /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; +} diff --git a/src/drivers/ipmi/ipmi_ops.h b/src/drivers/ipmi/ipmi_ops.h new file mode 100644 index 0000000..f293075 --- /dev/null +++ b/src/drivers/ipmi/ipmi_ops.h @@ -0,0 +1,57 @@ +#ifndef __IPMI_OPS_H +#define __IPMI_OPS_H +/* + * 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 <types.h> +#include "ipmi_kcs.h" +#define IPMI_BMC_RESET_WDG_TIMER 0x22 +#define IPMI_BMC_SET_WDG_TIMER 0x24 +#define IPMI_BMC_GET_WDG_TIMER 0x25 + +/* BMC watchdog timeout action */ +enum ipmi_bmc_timeout_action_type { + TIMEOUT_NO_ACTION = 0x00, + TIMEOUT_HARD_RESET = 0x01, + TIMEOUT_POWER_DOWN = 0x02, + TIMEOUT_POWER_CYCLE = 0x03, +}; +/* BMC Watchdog timer */ +struct ipmi_wdt_req { + uint8_t timer_use; + uint8_t timer_actions; + uint8_t pretimeout_interval; + uint8_t timer_use_expiration_flags_clr; + uint16_t initial_countdown_val; +} __packed; + +struct ipmi_wdt_rsp { + struct ipmi_rsp resp; + struct ipmi_wdt_req data; + uint16_t present_countdown_val; +} __packed; + +/* + * Initialize and start BMC FRB2 watchdog timer with the + * provided timer countdown and action values. + * Returns CB_SUCCESS on success and CB_ERR if an error occurred + */ +enum cb_err ipmi_init_and_start_bmc_wdt(const int port, uint16_t countdown, + uint8_t action); +/* Returns CB_SUCCESS on success and CB_ERR if an error occurred */ +enum cb_err ipmi_stop_bmc_wdt(const int port); + +#endif