blob: cab7f6dfae5c20da41897d33f2d7840eec29bd53 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Johnny Linf4abe512019-10-21 09:54:36 +08002
3#include <console/console.h>
4#include "ipmi_ops.h"
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +03005#include "ipmi_if.h"
Johnny Lin53509cf2019-11-14 14:55:04 +08006#include <string.h>
Elyes HAOUAS4f66cb92019-12-01 13:21:52 +01007#include <types.h>
Johnny Linf4abe512019-10-21 09:54:36 +08008
9enum cb_err ipmi_init_and_start_bmc_wdt(const int port, uint16_t countdown,
10 uint8_t action)
11{
12 int ret;
13 struct ipmi_wdt_req req = {0};
14 struct ipmi_rsp rsp;
15 printk(BIOS_INFO, "Initializing IPMI BMC watchdog timer\n");
16 /* BIOS FRB2 */
17 req.timer_use = 1;
18 req.timer_actions = action;
19 /* clear BIOS FRB2 expiration flag */
20 req.timer_use_expiration_flags_clr = 2;
21 req.initial_countdown_val = countdown;
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030022 ret = ipmi_message(port, IPMI_NETFN_APPLICATION, 0x0,
Johnny Linf4abe512019-10-21 09:54:36 +080023 IPMI_BMC_SET_WDG_TIMER,
Elyes Haouas1ef547e2022-11-18 15:05:39 +010024 (const unsigned char *)&req, sizeof(req),
25 (unsigned char *)&rsp, sizeof(rsp));
Johnny Linf4abe512019-10-21 09:54:36 +080026
27 if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) {
28 printk(BIOS_ERR, "IPMI: %s set wdt command failed "
29 "(ret=%d resp=0x%x), failed to initialize and start "
30 "IPMI BMC watchdog timer\n", __func__,
31 ret, rsp.completion_code);
32 return CB_ERR;
33 }
34
35 /* Reset command to start timer */
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030036 ret = ipmi_message(port, IPMI_NETFN_APPLICATION, 0x0,
Johnny Linf4abe512019-10-21 09:54:36 +080037 IPMI_BMC_RESET_WDG_TIMER, NULL, 0,
Elyes Haouas1ef547e2022-11-18 15:05:39 +010038 (unsigned char *)&rsp, sizeof(rsp));
Johnny Linf4abe512019-10-21 09:54:36 +080039
40 if (ret < sizeof(struct ipmi_rsp) || rsp.completion_code) {
41 printk(BIOS_ERR, "IPMI: %s reset wdt command failed "
42 "(ret=%d resp=0x%x), failed to initialize and start "
43 "IPMI BMC watchdog timer\n", __func__,
44 ret, rsp.completion_code);
45 return CB_ERR;
46 }
47
48 printk(BIOS_INFO, "IPMI BMC watchdog initialized and started.\n");
49 return CB_SUCCESS;
50}
51
52enum cb_err ipmi_stop_bmc_wdt(const int port)
53{
54 int ret;
55 struct ipmi_wdt_req req;
56 struct ipmi_wdt_rsp rsp = {0};
57 struct ipmi_rsp resp;
58
59 /* Get current timer first */
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030060 ret = ipmi_message(port, IPMI_NETFN_APPLICATION, 0x0,
Johnny Linf4abe512019-10-21 09:54:36 +080061 IPMI_BMC_GET_WDG_TIMER, NULL, 0,
Elyes Haouas1ef547e2022-11-18 15:05:39 +010062 (unsigned char *)&rsp, sizeof(rsp));
Johnny Linf4abe512019-10-21 09:54:36 +080063
64 if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
65 printk(BIOS_ERR, "IPMI: %s get wdt command failed "
66 "(ret=%d resp=0x%x), IPMI BMC watchdog timer may still "
67 "be running\n", __func__, ret,
68 rsp.resp.completion_code);
69 return CB_ERR;
70 }
71 /* If bit 6 in timer_use is 0 then it's already stopped. */
72 if (!(rsp.data.timer_use & (1 << 6))) {
73 printk(BIOS_DEBUG, "IPMI BMC watchdog is already stopped\n");
74 return CB_SUCCESS;
75 }
76 /* Set timer stop running by clearing bit 6. */
77 rsp.data.timer_use &= ~(1 << 6);
78 rsp.data.initial_countdown_val = 0;
79 req = rsp.data;
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +030080 ret = ipmi_message(port, IPMI_NETFN_APPLICATION, 0x0,
Johnny Linf4abe512019-10-21 09:54:36 +080081 IPMI_BMC_SET_WDG_TIMER,
Elyes Haouas1ef547e2022-11-18 15:05:39 +010082 (const unsigned char *)&req, sizeof(req),
83 (unsigned char *)&resp, sizeof(resp));
Johnny Linf4abe512019-10-21 09:54:36 +080084
85 if (ret < sizeof(struct ipmi_rsp) || resp.completion_code) {
86 printk(BIOS_ERR, "IPMI: %s set wdt command stop timer failed "
87 "(ret=%d resp=0x%x), failed to stop IPMI "
88 "BMC watchdog timer\n", __func__, ret,
89 resp.completion_code);
90 return CB_ERR;
91 }
92 printk(BIOS_DEBUG, "IPMI BMC watchdog is stopped\n");
93
94 return CB_SUCCESS;
95}
Johnny Lin53509cf2019-11-14 14:55:04 +080096
97enum cb_err ipmi_get_system_guid(const int port, uint8_t *uuid)
98{
99 int ret;
100 struct ipmi_get_system_guid_rsp rsp;
101
102 if (uuid == NULL) {
103 printk(BIOS_ERR, "%s failed, null pointer parameter\n",
104 __func__);
105 return CB_ERR;
106 }
107
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +0300108 ret = ipmi_message(port, IPMI_NETFN_APPLICATION, 0x0,
Johnny Lin53509cf2019-11-14 14:55:04 +0800109 IPMI_BMC_GET_SYSTEM_GUID, NULL, 0,
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100110 (unsigned char *)&rsp, sizeof(rsp));
Johnny Lin53509cf2019-11-14 14:55:04 +0800111
112 if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
113 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
114 __func__, ret, rsp.resp.completion_code);
115 return CB_ERR;
116 }
117
118 memcpy(uuid, rsp.data, 16);
119 return CB_SUCCESS;
120}
Morgan Jangea9787a2020-04-09 13:50:43 +0800121
122enum cb_err ipmi_add_sel(const int port, struct sel_event_record *sel)
123{
124 int ret;
125 struct ipmi_add_sel_rsp rsp;
126
127 if (sel == NULL) {
Arthur Heymans478da722021-03-25 10:09:23 +0100128 printk(BIOS_ERR, "%s failed, system event log is not present.\n", __func__);
Morgan Jangea9787a2020-04-09 13:50:43 +0800129 return CB_ERR;
130 }
131
Sergii Dmytrukef7dd5d2021-10-22 01:02:32 +0300132 ret = ipmi_message(port, IPMI_NETFN_STORAGE, 0x0,
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100133 IPMI_ADD_SEL_ENTRY, (const unsigned char *)sel,
134 16, (unsigned char *)&rsp, sizeof(rsp));
Morgan Jangea9787a2020-04-09 13:50:43 +0800135
136 if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
137 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
138 __func__, ret, rsp.resp.completion_code);
139 return CB_ERR;
140 }
141 return CB_SUCCESS;
142}