ipmi.c
 1  /* SPDX-License-Identifier: GPL-2.0-or-later */
 2  
 3  #include <console/console.h>
 4  #include <drivers/ipmi/ipmi_if.h>
 5  #include <drivers/ipmi/ipmi_ops.h>
 6  #include <drivers/ipmi/ocp/ipmi_ocp.h>
 7  #include <drivers/ocp/include/vpd.h>
 8  #include <drivers/vpd/vpd.h>
 9  #include <types.h>
10  
11  #include "ipmi.h"
12  
13  enum cb_err ipmi_get_slot_id(uint8_t *slot_id)
14  {
15  	int ret;
16  	struct ipmi_config_rsp {
17  		struct ipmi_rsp resp;
18  		uint8_t board_sku_id;
19  		uint8_t board_rev_id;
20  		uint8_t slot_id;
21  		uint8_t slot_config_id;
22  	} __packed;
23  	struct ipmi_config_rsp rsp;
24  
25  	ret = ipmi_message(CONFIG_BMC_KCS_BASE, IPMI_NETFN_OEM, 0x0, IPMI_OEM_GET_BOARD_ID, NULL, 0, (unsigned char *)&rsp, sizeof(rsp));
26  
27  	if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
28  		printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n", __func__, ret, rsp.resp.completion_code);
29  		return CB_ERR;
30  	}
31  	*slot_id = rsp.slot_id;
32  	return CB_SUCCESS;
33  }
34  
35  void init_frb2_wdt(void)
36  {
37  	uint8_t enable;
38  	int action, countdown;
39  
40  	if (vpd_get_bool(FRB2_TIMER, VPD_RW_THEN_RO, &enable)) {
41  		printk(BIOS_DEBUG, "Got VPD %s value: %d\n", FRB2_TIMER, enable);
42  	} else {
43  		printk(BIOS_INFO, "Not able to get VPD %s, default set to %d\n", FRB2_TIMER,
44  			FRB2_TIMER_DEFAULT);
45  		enable = FRB2_TIMER_DEFAULT;
46  	}
47  
48  	if (enable) {
49  		if (vpd_get_int(FRB2_COUNTDOWN, VPD_RW_THEN_RO, &countdown)) {
50  			printk(BIOS_DEBUG, "FRB2 timer countdown set to: %d ms\n",
51  				countdown * 100);
52  		} else {
53  			printk(BIOS_DEBUG, "FRB2 timer use default value: %d ms\n",
54  				FRB2_COUNTDOWN_DEFAULT * 100);
55  			countdown = FRB2_COUNTDOWN_DEFAULT;
56  		}
57  
58  		if (vpd_get_int(FRB2_ACTION, VPD_RW_THEN_RO, &action)) {
59  			printk(BIOS_DEBUG, "FRB2 timer action set to: %d\n", action);
60  		} else {
61  			printk(BIOS_DEBUG, "FRB2 timer action use default value: %d\n",
62  				FRB2_ACTION_DEFAULT);
63  			action = FRB2_ACTION_DEFAULT;
64  		}
65  		ipmi_init_and_start_bmc_wdt(CONFIG_BMC_KCS_BASE, (uint16_t)countdown,
66  			(uint8_t)action);
67  	} else {
68  		printk(BIOS_DEBUG, "Disable FRB2 timer\n");
69  		ipmi_stop_bmc_wdt(CONFIG_BMC_KCS_BASE);
70  	}
71  }