blob: b10755fd97ae16005939b44348cc92984d471fa2 [file] [log] [blame]
Jonathan Zhang830fec32022-10-21 18:31:54 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <console/console.h>
4#include <drivers/ipmi/ipmi_if.h>
5#include <string.h>
6
7#include "ipmi_ocp.h"
8
9static int ipmi_add_sel_entry(int port, unsigned char *data, int size)
10{
11 return ipmi_message(port, IPMI_NETFN_STORAGE, 0, IPMI_ADD_SEL_ENTRY, data, size,
12 NULL, 0);
13}
14
15void ipmi_send_to_bmc(unsigned char *data, size_t size)
16{
17 if (CONFIG(IPMI_KCS)) {
18 _Static_assert(CONFIG_BMC_KCS_BASE != 0,
19 "\tBMC_ERROR: Unable to send record: Port #:0\n");
20
21 ipmi_add_sel_entry(CONFIG_BMC_KCS_BASE, data, size);
22 }
23}
24
25void ipmi_send_sel_iio_err(uint8_t iio_stack_num, uint8_t err_id)
26{
27 struct ipmi_sel_iio_err ubslp = {
28 .record_id = SEL_RECORD_ID,
29 .record_type = CONFIG_RAS_SEL_VENDOR_ID,
30 .general_info = SEL_PCIE_IIO_ERR,
31 .iio_stack_num = iio_stack_num,
32 .iio_err_id = err_id,
33 };
34
35 ipmi_send_to_bmc((unsigned char *)&ubslp, sizeof(ubslp));
36 printk(BIOS_DEBUG, "\tsending PCIE IIO device error record to BMC\n");
37 printk(BIOS_DEBUG, "\tstack # = %x\n", ubslp.iio_stack_num);
38}
39
40void ipmi_send_sel_pcie_dev_err(pci_devfn_t bdf, uint16_t prmry_cnt, uint8_t sec_id,
41 uint8_t prmry_id)
42{
43 struct pci_dev_fn *inbdf = (struct pci_dev_fn *)&bdf;
44 struct ipmi_sel_pcie_dev_err ubslp = {
45 .record_id = SEL_RECORD_ID,
46 .record_type = CONFIG_RAS_SEL_VENDOR_ID,
47 .general_info = SEL_PCIE_DEV_ERR,
48 .timestamp = 0, /* BMC will apply timestamp */
49 .aux_loc = 0,
50 .bdf.bus = inbdf->bus,
51 .bdf.dev = inbdf->dev,
52 .bdf.func = inbdf->func >> 12,
53 .primary_err_count = prmry_cnt,
54 .primary_id = prmry_id,
55 .secondary_id = sec_id,
56 };
57
58 ipmi_send_to_bmc((unsigned char *)&ubslp, sizeof(ubslp));
59 printk(BIOS_DEBUG, "\tsending PCIE device error record to BMC\n");
60 printk(BIOS_DEBUG, "\tbdf = %x:%x:%x\n", ubslp.bdf.bus, ubslp.bdf.dev, ubslp.bdf.func);
61 printk(BIOS_DEBUG, "\tubslp.primary_id = %x\n", ubslp.primary_id);
62 printk(BIOS_DEBUG, "\tsecondary_id = %x\n", ubslp.secondary_id);
63}
64
65void ipmi_send_sel_pcie_dev_fail(uint16_t sts_reg, uint16_t src_id, enum fail_type code)
66{
67 struct ipmi_sel_pcie_dev_fail ubslp = {
68 .record_id = SEL_RECORD_ID,
69 .record_type = CONFIG_RAS_SEL_VENDOR_ID,
70 .general_info = SEL_PCIE_DEV_FAIL_ID,
71 .timestamp = 0, /* BMC will apply timestamp */
72 .type = code,
73 .failure_details1 = sts_reg,
74 .failure_details2 = src_id,
75 };
76
77 ipmi_send_to_bmc((unsigned char *)&ubslp, sizeof(ubslp));
78 printk(BIOS_DEBUG, "\tsending PCI device FAILURE record to BMC\n");
79 printk(BIOS_DEBUG, "\terror_code = %x, src_id = %x\n", ubslp.type,
80 ubslp.failure_details2);
81}
Jonathan Zhang5c1dcd52022-10-21 18:55:38 -070082
83enum cb_err ipmi_get_board_config(const int port, struct ipmi_config_rsp *config)
84{
85 int ret;
86 struct ipmi_oem_rsp {
87 struct ipmi_rsp resp;
88 struct ipmi_config_rsp data;
89 } __packed;
90
91 struct ipmi_oem_rsp rsp;
92
93 ret = ipmi_message(port, IPMI_NETFN_OEM, 0x0, IPMI_OEM_GET_BOARD_ID, NULL, 0,
94 (unsigned char *)&rsp, sizeof(rsp));
95 if (ret < sizeof(struct ipmi_rsp) || rsp.resp.completion_code) {
96 printk(BIOS_ERR, "IPMI: %s command failed (ret=%d resp=0x%x)\n",
97 __func__, ret, rsp.resp.completion_code);
98 return CB_ERR;
99 }
100 *config = rsp.data;
101 return CB_SUCCESS;
102}
103
104__weak uint8_t get_blade_id(void)
105{
106 struct ipmi_config_rsp rsp = {.slot_id = UINT8_MAX};
107
108 if (CONFIG(IPMI_KCS) && CONFIG_BMC_KCS_BASE) {
109 if (ipmi_get_board_config(CONFIG_BMC_KCS_BASE, &rsp) != CB_SUCCESS)
110 return UINT8_MAX;
111 }
112 return rsp.slot_id;
113}